Control flow
The flow of the code is the order in which the statements, functions or instructions are executed. By default the code is executed line by line:
But this order can be altered in different ways, and these modifications are known as control flow. We could:
- Choose to execute some statements only if some condition is met.
- Run the same code over and over again for every item.
- Create new functions and call them.
To understand the control of the flow of execution we need to understand the concept of a block of code. A block is a set of lines that are grouped together, for instance, the set of lines that will be executed only when a given condition if met.