Summary: Allow labeled breaks to work on *any* block
--- Comment #0 from monarchdo...@gmail.com 2012-09-05 06:35:59 PDT ---
D gives the possibility of multiple-breaking out (nested) while/for blocks
using labeled breaks.
I think it would be beneficial to extend this to being able to break out of any
"block", as long as it is labeled:
break label; // jumps to "here:"
// break lands here
The main use case here would actually be to replace the "triangle if" pattern:
Which would become
if(!condition1) break conditional_block;
if(!condition2) break conditional_block;
if(!condition3) break conditional_block;
if(!condition4) break conditional_block;
The usual "workaround" to the "triangle if" pattern is to move it to it's own
function, and *return* from it. The disadvantage is that it burdens the
developer with a whole extra function. The "breakable block" has the advantage
of not breaking the logic flow of the current function.
Another workaround, the "do_while_false" is also possible:
However, my experience is that this pattern tends to be confusing for readers
that expected a loop: The actual condition "while(false)" is only documented
near the end.
Further more, given both the above workarounds, neither scale should you want
to nest a double break.
Conclusion: Generic breakable labeled blocks. It works better and is
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------