8.4. while Statement

Python's while is the first looping statement we will look at in this chapter. In fact, it is a conditional looping statement. In comparison with an if statement where a true expression will result in a single execution of the if clause suite, the suite in a while clause will be executed continuously in a loop until that condition is no longer satisfied.

8.4.1. General Syntax

Here is the general syntax for a while loop:

							while
							expression:
							suite_to_repeat
						

The suite_to_repeat clause of the while loop will be executed continuously in a loop until expression evaluates to Boolean false. This type of looping mechanism is often used in a counting situation, such as the example in the next subsection.

8.4.2. Counting Loops

Get Core Python 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.