Do Loop with Variable

Quirin Schroll qs.il.paperinik at gmail.com
Tue Jul 8 16:40:24 UTC 2025


I have the feeling this isn’t gonna fly, but I’ll say it anyways 
because maybe someone finds a solution.
```d
do (int x = 0)
{ }
while (++x < 10);
```
which would be equivalent to
```d
{
     int x = 0;
     do
     { }
     while (++x < 10);
}
```

Obviously, we can’t just parse `do` plus the opening parenthesis 
because things like `do (x + y).ufcs while (…)` certainly exist. 
But it can be parsed:

After `do` plus opening parenthesis, scan for the closing 
parenthesis. From there, if an opening brace follows, scan for 
the closing brace. If the closing brace is followed by `while`, 
it’s the new construct.

The new construct must use braces, otherwise ambiguity lurks.


More information about the dip.ideas mailing list