3/24/2026 at 6:51:02 AM
It might sound easy to fix just a little detail that disturbs you and keep the rest as it is, but it's rarely feasible.If we ban side effects from expressions, we must change the "for" syntax too, because the third "argument" currently is an expression. It should be a statement instead. Let's see...
for (int i=0; i<n; ++i) // old
for (int i=0; i<n; i+=1;) // new
What about the typical 2-variable loop? for (int i=0,j=n; i<j; ++i,--j) // old
for (int i=0,j=n; i<j; {i+=1;j-=1;}) // maybe?
Or we simply forbid all this and force the increment and decrement in the body: for (int i=0,j=n; i<j; ;) {
...
i+=1;
j-=1;
}
This is throwing the baby out with the bathwater!And finally, if the third argument is a statement, would a break or continue be accepted there as well? A nested for? Sure, these are examples of abusing the syntax, but so is using x and ++x in the same expression.
My conclusion is that some constructs are so powerful that they can both simplify our code and make it unreadable. The choice how to use them is ours.
by teo_zero