Learn Python the Hard Way: A Deceptively Simple Introduction to the Terrifyingly Beautiful World of Computers and Data Science, 5th Edition
by Zed A. Shaw
Exercise 34
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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access