image
image
image

Using While loop with else

image

If the condition is false and no break occurs, a while loop’s else part runs.

Example

Start IDLE.

Navigate to the File menu and click New Window.

Type the following:

track = 0

while track< 4:

print("Within the loop")

track = track + 1

else:

print("Now within the else segment")