Flow of Control

  • Joe Pitt-Francis
  • Jonathan Whiteley
Part of the Undergraduate Topics in Computer Science book series (UTICS)


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.

Copyright information

© Springer International Publishing AG, part of Springer Nature 2017

Authors and Affiliations

  1. 1.University of OxfordOxfordUK

Personalised recommendations