4 ms·
@OskarS I agree with you... In fact, I have been avoiding gotos as a matter of principle for years and now reading the different discussions, I think I was misl
by clauderoux 2y ago
@OskarS I agree with you... In fact, I have been avoiding gotos as a matter of principle for years and now reading the different discussions, I think I was misled. This case is very, very common. You have 3 intertwined loops and you want to get out. The traditional solution is to add some intermediate variables to propagate the end of the loops, with a cascade "if (toto) break;" which are far from being exquisitely elegant...
Using a function for that is really adding some more complexity and some more stuff on the stack for nothing.
- clauderoux 2y agoAlso as a matter of technology, using "if" to get out of loops is bad with modern processors and their internal predictive algos. My solution for a long time was to add the test within the "for" itself, but it is often confusing for users.
- OskarS 2y agoExactly. The only reason not to use goto here is because of a dogmatic opposition to ever using goto. In fact, this is a rare case where goto makes the flow of the program more clear rather than less clear, and alternate solutions are just worse.