What is control flow?
Programs often need to take one action in certain cases, and different actions in different cases. Also, programs often need to repeat actions multiple times. These two ideas are called control flow.
Conditional statements (or branches) allow us to make choices about which lines of code to execute based on the values of variables. In python, we will learn if
, if-else
, and if
-ladder statements.
Iterative statements (or loops) allow us to repeat lines of code either a specific number of times, or based on the value of a variable, or based on the contents of stored data. In python we will learn for
-loop statements and while
-loop statements.
This chapter covers writing conditional statements (branches) to control the flow of your program. The following chapter covers writing iterative statements (loops).