Comment #0 by qs.il.paperinik — 2024-07-23T14:17:42Z
A `for` loop essentially is syntax sugar for a `while` loop, except that a `while` loop can declare a variable in its condition, but a `for` loop can’t.
A variable declared in the condition can be mimicked:
```d
for (int i; int diff = 5 - i; ++i) { } // error
for ({int i; int diff; } (diff = 5 - i) == true; ++i) { }
```
Grammar change:
```diff
ForStatement:
- for ( Initialize Test? ; Increment? ) ScopeStatement
+ for ( Initialize IfCondition? ; Increment? ) ScopeStatement
- Test:
- Expression
```
Not also that declarations in `for` conditions are allowed in C++.
Comment #1 by robert.schadek — 2024-12-13T19:36:37Z