Usage of the while Loop
Learn how to use the while loop in a Python program.
We'll cover the following
The while
loop can be used in three situations:
- Repeating a set of statements until a condition remains
True
. - Repeating a set of statements a finite number of times.
- Iterating through a string, list, and tuple.
First usage of the while
loop
When we use the while
loop to repeat a set of statements until a condition remains True
, it means that we don’t know beforehand how many times the statements need to be executed.
Get hands-on with 1400+ tech skills courses.