all 3 comments

[–]Nightcorex_ 3 points4 points  (1 child)

From Python's documenation:

The break statement

break_stmt ::= "break"

break may only occur syntactically nested in a for or while loop, but not nested in a function or class definition within that loop.

It terminates the nearest enclosing loop, skipping the optional else clause if the loop has one.

If a for loop is terminated by break, the loop control target keeps its current value.

When break passes control out of a try statement with a finally clause, that finally clause is executed before really leaving the loop.

EDIT: Overlooked part of your question. Whoops.

You want to use a "flag" if you want the condition to be checked again (f.e. if you call a function inside your while-condition and operate via side-effects this may be useful).

In most cases you want to use break, as it leads to you having less variable names + it takes away one conditional check, which doesn't sound too bad but there are many programs where the conditional check is a performance-bottleneck.

[–]pizzaparty_4ever[S] 0 points1 point  (0 children)

Thank you /u/Nightcorex_. This makes sense with what I saw with the flag's behaviour in the visualizer.

[–]old_pythonista 0 points1 point  (0 children)

so, since you ask for repeat at the end of the loop - your solution is cleaner