I want to shorten the process time of my script, and in order to do that I need to know how I can exit a loop if some condition is met.

For instance I'm running through all my faces and if something is True, then it should stop the loop and not just 1 step:

for i in range(n_faces):
    if *something* is True:
        continue

I know that by doing this, I can skip just 1 step, but how do I skip the whole loop after *something* is True?

有帮助吗?

解决方案

You can use the break statement to break out from the loop, see the Python Documentation

4.4. break and continue Statements, and else Clauses on Loops

The break statement, like in C, breaks out of the smallest enclosing for or while loop.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top