4 ms·
Do "for" and "while" constructs also seem silly? After all they "compile to a loop" as well. The purpose of all these loop constructs is to place constraints o
by dTal 5y ago
Do "for" and "while" constructs also seem silly? After all they "compile to a loop" as well.
The purpose of all these loop constructs is to place constraints on some essential aspect of the loop up front, thus narrowing the possible range of effects of that wicked goto, by encoding common patterns. "For" loops guarantee the number of iterations. "While" loops guarantee the exit condition. And tail recursion guarantees what state gets modified in the loop.
It is strange the way you say "better off doing it in a loop". As you say, it is a loop. What construct would you prefer? GOTO?