Python TutorialLesson 20Free preview
Python While Loops
This lesson is part of Python · All levels
Summary
While the loop executes a block of code while the condition in it is still worth True, it is therefore suitable for unknown repetitions of the exact number. The control variable must be updated within the block so that the conditions can change and the repetition stops. If the condition never becomes False, the program will be trapped in an infinite loop.
Key points
- While checking the condition before and during each iteration running.
- The control variable needs to be updated so the loop is complete.
- The colon and the indentation are the same as if.
- The break statement stopped the loop earlier than inside the block.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.