4 ms·
In a situation like that I would usually define a boolean before entering the top loop, and set that true within once a condition is met, causing all the outer
by noduerme 5y ago
In a situation like that I would usually define a boolean before entering the top loop, and set that true within once a condition is met, causing all the outer loops to break if that condition is true. I can't imagine there would be a major speed difference in some other way of breaking all the loops to jump to a different line of code.
- withinboredom 5y agoThat means once it’s set to true, all the inner loops would need to at least finish that iteration. That could be a huge speed difference at a minimum or a completely wrong implementation.
- simion314 5y agothis means you do a if check each loop, this is bad if you do some say image filter/effect where you work with big loops. end you get some nested if and break inside the code, is much more readable to just jump out.
- Dylan16807 5y agoI would argue that having to do that is not in fact a 'proper' loop. Your way and goto are both workarounds for a missing control flow construct. For gosub, what's the issue? It is a method call.
- slightwinder 5y agoPythons for-loop is not working with boolean, so using one would mean to uglify the code. A goto would simplify the workflow by removing 1-2 lines for each additional loop.