9/2/26Less than 1 minuteAbout 137 words
Concept: while loop
A while loop requires a test expression that evaluates to True or False. While the test expression evaluates to True, the block of code beneath it is executed. When the test expression evaluates to False, the loop is exited, and the program continues executing the code that follows the loop.
Warning
It is extremely important to ensure that the test expression will eventually evaluate to False, otherwise the loop will never exit, and the program will run indefinitely.
while test_expression:
# This code runs only if test_expression is True
do_something()
# Update the test expression to eventually become False
test_expression = update_test_expression()