3 ms·
Because the classic for loop is prone to off-by-one errors, and it's unnecessarily boilerplatey for simple cases. OTOH complex cases that take advantage of cust
by pornel 4y ago
Because the classic for loop is prone to off-by-one errors, and it's unnecessarily boilerplatey for simple cases. OTOH complex cases that take advantage of customizing the three clauses or independently modify iteration variable(s) are usually "clever", not in a good way.
- giancarlostoro 4y agoYou can still have it but add more modern syntax for looping. Hell Java has "goto" reserved if I remember correctly.
- pornel 4y agoAll languages with a simplified `for` loop have kept `while` for the other cases. That makes the old `for` just a redundant syntax.
- david2ndaccount 4y agoZig supports the 2nd and 3rd clause already in its while loop. Would it kill it to accept an initializer and look more like other languages instead of having a special snowflake syntax. Is this (note the enclosing braces) { var thing = thinger(); while(cond(thing)) : (mutate(thing)){ // do whatever } } really better than this? for(var thing = thinger(); cond(thing); mutate(thing)){ // do whatever }