June 2017
Beginner
352 pages
8h 39m
English
Python has two types of loop: for-loops and while-loops. We've already briefly encountered for-loops back when we introduced significant whitespace, and we'll return to them soon, but right now we'll cover while-loops.
The While-loops in Python are introduced by the while keyword, which is followed by a boolean expression. As with the condition for if-statements, the expression is implicitly converted to a boolean value as if it has been passed to the bool() constructor. The while statement is terminated by a colon because it introduces a new block.
Let's write a loop at the REPL which counts down from five to one. We'll initialize a counter variable called c to five, and keep looping until we reach ...
Read now
Unlock full access