Chapter 3 Introduction to Control Flow

The basis of computer programming in any language begins with control flow.

Control flow (or flow of control) is the order function calls, instructions, and statements are executed or evaluate when any program is running.

Imagine that you would like to run an operation several times, until a condition is met. One option, is to rewrite the same code, while changing part of the syntax, that number of times you wish. Alternatively, we could write our code using control flow, and iterate through the same operation that will evaluate and stop until a certain condition is met. This last option usually implies in a much shorter, clearer and less complex form of writing code.

It is advantageous, for any programmer, to think in terms of in terms of control flow, and therefore have structured programs, because:

  1. The complexity and time of the task at hand is greatly decreased;

  2. A logical structure also means that the code has increased clarity;

  3. It also facilitates collaboration, and therefore increases productivity.

3.0.1 Building blocks of control flow

There are many building blocks of control flow programming:

  • Sequencing, which executes or evaluates something sequentially;
  • Selection, which performs operations ìf or unless certain conditions are met;
  • Iteration, which repeats an operation while, until or for a determined number of times;
  • Procedural abstraction, which involves a subroutine, nested call;
  • Recursion
  • Concurrency, which does several operations at the same time;
  • Exception handling and speculation
  • Non-determinism, which does an operation