Control Flow in Python
To make a program do different things for different inputs, we need loops and branches.
In the first article of this series, we set up python for the rest of the series. In the second article, we introduced some fundamental objects and operators on those objects. At this point, we know enough to make working programs, but these programs can only do one thing. To fix the problem, we need to introduce branches, loops, and functions.
- Previous Article
- Next Article
- All Articles
Branches allow us to do different things in different scenarios, loops allow us to do the same thing over and over and over again, and functions allow us to greatly simplify our code.
Topics Covered
As always, here are the topics covered. If you know these well, skip this article (and maybe read one of my other articles).
Boolean Values
:True
andFalse
if
: (conditional branches/selection statements)for
andwhile
: (loops)break
andcontinue
- List Comprehension
range
enumerate
def
: (functions)