4 ms·
You would never use nested if statements for performance reasons. The conditions in any modern language will short circuit, which will give the equivalent behav
by openasocket 9y ago
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.
- taneq 9y agoNested 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.)