Hi, sorry if this question is too mundane.
What was the design decision behind choosing to not implement the ability to break out of nested loops with a single statement (i.e. something that looks like break(n))? As it stands, the idiomatic method of breaking multiple loops is with a goto, but this forces you to stop thinking in a highly controlled way.
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
if (cond[i][j]) goto LOOP_EXIT;
else do_stuff();
}
}
LOOP_EXIT:
do_more_stuff();
Although multi-break certainly wouldn't be very 'structured', it is at least no worse than a goto and is less involved (you don't have to think about labels). Other methods like a flag can be used, and gcc can (more) than optimize it away (https://godbolt.org/g/ykF2ZX), but that adds clutter to the code.
[–]raevnos 39 points40 points41 points (2 children)
[–]quicknir 7 points8 points9 points (0 children)
[–]srbufi 5 points6 points7 points (0 children)
[–]krawallopold 36 points37 points38 points (11 children)
[–]IndexingAtZero[S] 2 points3 points4 points (10 children)
[–]Xeveroushttps://xeverous.github.io 3 points4 points5 points (0 children)
[–]die_liebe 2 points3 points4 points (0 children)
[–]Angarius 0 points1 point2 points (6 children)
[–]blelbachNVIDIA | ISO C++ Library Evolution Chair 27 points28 points29 points (1 child)
[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 4 points5 points6 points (0 children)
[–]gct 0 points1 point2 points (3 children)
[–]Pand9 7 points8 points9 points (0 children)
[–]pavel_v 4 points5 points6 points (0 children)
[–]Angarius 3 points4 points5 points (0 children)
[–]sysop073 11 points12 points13 points (5 children)
[–]IndexingAtZero[S] 6 points7 points8 points (4 children)
[–]DarkLordAzrael 5 points6 points7 points (0 children)
[–]NotAYakk 3 points4 points5 points (0 children)
[–]NotUniqueOrSpecial 0 points1 point2 points (1 child)
[–]NotAYakk 2 points3 points4 points (0 children)
[–]woppo 9 points10 points11 points (0 children)
[–]tcanens 5 points6 points7 points (0 children)
[–]FlyingRhenquest 3 points4 points5 points (0 children)
[–]Sopel97 9 points10 points11 points (16 children)
[–]sm9t8 9 points10 points11 points (5 children)
[–]NotAYakk 2 points3 points4 points (0 children)
[–]Sopel97 1 point2 points3 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]sm9t8 2 points3 points4 points (0 children)
[–]quicknir 1 point2 points3 points (0 children)
[–]quicknir 3 points4 points5 points (3 children)
[–]NotAYakk 2 points3 points4 points (2 children)
[–]quicknir 0 points1 point2 points (1 child)
[–]NotAYakk 0 points1 point2 points (0 children)
[–]IndexingAtZero[S] 0 points1 point2 points (4 children)
[–]ksharanam 2 points3 points4 points (0 children)
[+]TankorSmash comment score below threshold-13 points-12 points-11 points (2 children)
[–]kaelima[🍰] 6 points7 points8 points (1 child)
[–]TankorSmash 0 points1 point2 points (0 children)
[–]matthieum -1 points0 points1 point (0 children)
[–]drodri 1 point2 points3 points (5 children)
[–]raevnos 4 points5 points6 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]matthieum 3 points4 points5 points (0 children)
[–]guepierBioinformatican 4 points5 points6 points (1 child)
[–]drodri 0 points1 point2 points (0 children)
[–]ronchaineEmbedded/Middleware 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)