Why use while if only iterating once ?

Dukc ajieskola at gmail.com
Tue Nov 6 12:27:53 UTC 2018


On Saturday, 3 November 2018 at 21:13:49 UTC, Jonathan M Davis 
wrote:
> There's a continue right above the default case. So, if the 
> code hits that point, it will loop back to the top.
>
> - Jonathan M Davis

There's also the benefit that FLAGS f exists only until the end 
of the loop, and thus won't be polluting the namespace later in 
the function.

Personally, when I want to make a block just for grouping code, I 
use if (true){} or static if (true){} depending on whether I want 
to it's variables go away afterwards.

IIRC, I could just use braces without any header intead of if 
(true){}, but the code block just isn't as easily distinquishable 
without anything at the top IMO.


More information about the Digitalmars-d-learn mailing list