Skip to main content

Flow of Control

  • Chapter
  • First Online:
Guide to Scientific Computing in C++

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

  • 216k Accesses

Abstract

In almost any computer program written for a scientific computing application we need to allow the computer to execute a collection of statements if—and only if—some criterion is met. For example, if we were writing a program to control the motion of a spacecraft travelling to Mars, the program would include lines of code that would control the safe landing of the spacecraft. It is imperative that the lines of code that instruct the motors to cut out are executed at exactly the right time. As with most programming languages, conditional branching may be achieved in C++ programs by using an if statement. Similarly we may use a while statement to execute a collection of statements until a specified condition is met, and a for loop to execute a collection of statements a specified number of times. This flow of control often depends on relations between operators (such as greater than) and on combinations of expressions (such as two conditions both being true). In this chapter we explain how to utilise these features of the C++ language.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Nobody knows what happened to the Mars Polar Lander in the last few seconds of its descent in 1999, but experts believe there was a bug in the landing gear sensor code. This bug involved accumulating weak signals from the landing gear and may have caused the retrorockets to cut out too early.

  2. 2.

    If p and q are the results of two calculations which ought to be equal, to within machine precision, then they many differ by about |p| \(\times \) DBL_EPSILON, since DBL_EPSILON \(\sim \)2e–16 is defined in #include <cfloat> to be smallest double precision floating point number such that 1.0+DBL_EPSILON is not equal to 1.0 when rounding errors are taken account of.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Joe Pitt-Francis .

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2017). Flow of Control. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-319-73132-2_2

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-73132-2_2

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-73131-5

  • Online ISBN: 978-3-319-73132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics