Python multi-level break and continue
Python multi-level break and continue
Posted Sep 1, 2022 12:42 UTC (Thu) by eru (subscriber, #2753)In reply to: Python multi-level break and continue by jezuch
Parent article: Python multi-level break and continue
Splitting code into smaller functions is often good practice, but not always. I often find it clearer to have the whole inline, so it can be seen at a glance, instead of lots of small functions used only once. The latter is like reading a text that keeps jumping into footnotes!
As a contribution to the fun syntax bikeshedding, a language I was involved in implementing had a loop roughly like this:
while cond1
while cond2
...
// Want to break out of both loop levels?
if satisfied
break foundIt
endwhile
endwhile foundIt
The break is a jump forward, so it makes sense the label is at the endwhile. Of course this wont work too well in Python that lacks a delimiter to mark the end of the loop, other than decreasing indentation.
Posted Sep 1, 2022 21:00 UTC (Thu)
by bartoc (guest, #124262)
[Link]
Keeping things inline can make optimization opportunities more clear and make anti-optimizations stick out more, as well.
Python multi-level break and continue
