WTF?

Robert Fraser fraserofthenight at gmail.com
Thu Mar 13 20:23:11 PDT 2008


BCS wrote:
> I'm not objecting but...
> 
> this compiles (1.026):
> 
> import std.stdio; void main()
> {
>     int j = 3;
>     for({ int i; if(j>2) i = 3; else i = 4; } i; i--)
>     {
>         writef("%d\n", i);
>     }
> }

I'm assuming that's equivalent to:

for(int i = j > 2 ? 3 : 4; 0 != i; i--)

...? If so, it is a bit strange-looking, but the initializer of a for is 
a statement, so why shouldn't a block statement be allowed there? 
Grammatically speaking, it'd be more odd if there was some arbitrary 
rule about for initializers.



More information about the Digitalmars-d mailing list