Python for-else Keywords

The code in the else block will execute if the for loop did not encounter a break.

Example

This code executes the else block:

Python
for x in range(1, 10):
    if x == 20:
        break;
else:
    print('Nothing found!')

Output

Nothing found!

Example - this code does not execute the else block:

Python
for x in range(1, 10):
    if x == 5:
        break;
else:
    print('Nothing found!')

There is no output.