WTF?

BCS ao at pathlink.com
Thu Mar 13 20:48:56 PDT 2008


Reply to Robert,

> 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.
> 

If I'd wondered, I have though it would be a declaration or list of declarations. 
Not a totally arbitrary statement.





More information about the Digitalmars-d mailing list