Skip to main content

Flow of Control

  • Chapter

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

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.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   29.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about 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| × DBL_EPSILON, since DBL_EPSILON ∼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.

References

Mathematical Methods and Linear Algebra

  1. Kreyszig, E.: Advanced Engineering Mathematics, 9th edn. Wiley, New York (2006)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Jonathan Whiteley .

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag London Limited

About this chapter

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2012). Flow of Control. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, London. https://doi.org/10.1007/978-1-4471-2736-9_2

Download citation

  • DOI: https://doi.org/10.1007/978-1-4471-2736-9_2

  • Publisher Name: Springer, London

  • Print ISBN: 978-1-4471-2735-2

  • Online ISBN: 978-1-4471-2736-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics