Lesson 18. Repeating tasks while conditions hold
After reading lesson 18, you’ll be able to
- Understand the syntax of another way to write a loop in a program
- Repeat actions while a certain condition is true
- Exit out of loops early
- Skip statements in a loop
In the previous lessons, you assumed that you knew the number of times you wanted to repeat a block of code. But suppose, for example, that you’re playing a game with your friend. Your friend is trying to guess a number that you have in mind. Do you know in advance how many times your friend will guess? Not really. You want to keep asking them to try again until they get it right. In this game, you don’t know how many times you want to repeat the task. Because you don’t know, you can’t use ...
Get Get Programming 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.