Unsure how many times to repeat code?
Python has the while keyword. Unlike the for loop which tests the condition first, the while loop execute the code first. Sometimes we don’t know how long sometimes will take.
A theoretical program could be (pseudocode):
Lets build an extended ‘guess the number game’:
x = 0
The program keeps repeating the code block while the condition (x!=5) is True. Once x equals 5, the program continues.
If a condition in a while loop is never met, it could cause the program to run forever or to freeze/crash.