News for hackers. Stuff that matters.
Re:Loop Exits and Structured Programming: Reopening the Deba... by erikpukinskis on Monday June 12, 2017 @05:45PM (#14541381)
Smells bad, but could legitimately be the correct structure. Depends on the problem and performance constraints. If you have a lot of conditionals and it's too expensive to run them all, nested ifs are correct. If you need to break from conditions arising from a multiple indexes, then nested loops are correct.

Dogma has no place in coding. Best practices give you a sense of smell. They don't tell you how to factor.

Re:Loop Exits and Structured Programming: Reopening the Deba... by openasocket on Monday June 12, 2017 @06:49PM (#14541763)
You would never use nested if statements for performance reasons. The conditions in any modern language will short circuit, which will give the equivalent behavior as manually making nested loops. Depending on the circumstances it might be more readable, but never more performant.
Re:Loop Exits and Structured Programming: Reopening the Deba... by taneq on Monday June 12, 2017 @09:39PM (#14542388)
Nested if-statements lets you avoid re-evaluating the conditions between if-statements. Short-circuit evaluation only partially addresses that.

It can be cleaner to cache the conditions in a few flags if you want to do it that way, though. I'm not saying deeply nested conditionals are pretty, just that there are some cases where they're quicker. (Of course, if you're scraping the bottom of the barrel for that kind of speedup then chances are, there are algorithmic improvements that will yield orders of magnitude more gains.)