Do Loop with Variable
Atila Neves
atila.neves at gmail.com
Thu Jul 31 08:38:18 UTC 2025
On Tuesday, 8 July 2025 at 16:40:24 UTC, Quirin Schroll wrote:
> 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.
I think this is of limited utility and there's a workaround.
More information about the dip.ideas
mailing list