Congratulations! You've just reinvented Ada's looping structure. Jean Ichbiah probably reinvented someone else's prior art.
This is de facto possible in a lot of languages, where you can create endless loops with programmed exits. For example, in Python:
while True:
do_stuff()
if not loop_continues:
break
do_more_stuff()
The reason so many languages have a test-at-top loop (while
), a test-at-bottom loop (do until
), and a counting/iterating loop (for
) is that those are the most common patterns, and most likely to be needed. But with modern break
("get me out of this loop!") and continue
("we're ready for the next iteration!") options, there really aren't nearly as many needs for bespoke loop syntax to cover all the options. Python, e.g., does with just for
and while
variants.
The early-exit ('break) and early-continue (break
) and early-continue () operations are well-structured, with only a few well-designed places they can take you (namely to the bottom/exit of the loop, or to the top of the loop). They are not the "I may jump to pretty much any line!" wildcards of the olden continue
GOTO`) operations are well-structured, with only a few well-designed places they can take you (namely to the bottom/exit of the loop, or to the top of the loop). They are not the "I may jump to pretty much any line!" wildcards of the olden GOTO
days, and so they can get you (and whatever optimizer your compiler toolchain is using) into many fewer sticky situations.
Given that we now have (pretty much irrespective of language used) good structured means to test and manage loop behavior, I'm unclear why anyone would have a strong preference. Test where it makes sense for the algorithm involved: At the top, at the bottom, or some place in between.