Member-only story
Learn Programming with Python — Controlling Execution Flow
In this instalment we’ll explore how to control which parts of your program are executed.
What is “Execution Control Flow”
At its simplest, every programmer, practically every day, will need to control if and when a particular statement should execute. Falling back on the ATM example introduced in the previous instalment in this series, “Learn Programming with Python — Introduction to Functions”, we know that the ATM should only issue cash if a series of test conditions are met. At the heart of execution control flow is the programmer’s intent to only execute certain functions of the program when they are needed, and otherwise not.
If … Elif … Else
Python is easy to read even for novices and non-programmers. This Python code is quite readable:
Except perhaps for line 2. Line 1 retrieves text input — called a string, from the terminal prompt. In line 2 we use the built-in int()
function to try to convert the argument to an integer. We need the age in…