manyspikes

Control flow

So far we have been writing code that executes sequentially, i.e. one line after the next. Now we will introduce a concept called control flow: the ability to conditionally execute some code, or manipulate the order in which the code is executed.

We will cover two main mechanisms:

  • Conditions
  • Loops

Conditions allow us to execute code depending on whether or not a condition is met. Loops allow us to execute the same lines of code more than just once. In the next sections, we will look at these two mechanisms in more detail.