while conditional:
# code block 1
[else:
# code block 2]
The while
loop is a general loop that keeps running the # code block 1
while the conditional
is True
. It runs the else
code block if the loop exists without hitting a break
statement.
This immediately exist the closest enclosing while
or for
loop statement, skipping its associated else
statement (if any).