Python 101 : Breaking out of a "while" loop - while ... else -

 We could use the "while ... else" construct to break out of a "while" loop as soon as a condition is fulfilled.

In the below example, we leave the loop as soon as the number "5" is found:

In the following example, the number "5" is not found and the "else" clause is executed:


Leave as a comment: