Exercise 33. While Loops

Now to totally blow your mind with a new loop, the while-loop. A while-loop will keep executing the code block under it as long as a Boolean expression is True.

Wait, you have been keeping up with the terminology, right? That if we write a line and end it with a : (colon) then that tells Python to start a new block of code? Then we indent and that’s the new code. This is all about structuring your programs so that Python knows what you mean. If you do not get that idea then go back and do some more work with if-statements, functions, and the for-loop until you get it.

Later on we’ll have some exercises that will train your brain to read these structures, similar to how we burned Boolean expressions into your brain.

Get Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.