suggested change to foreach index
Sean Kelly
sean at f4.ca
Wed Jun 7 20:26:50 PDT 2006
What's weird to me is if I do this:
void main()
{
int i;
char[] arr = "abc def";
foreach( i, c; arr )
{
printf( "%i\n", i );
if(' ' == c)
break;
}
printf( "\n%i\n", i );
}
Then the output is:
0
1
2
3
0
So the code compiles without a type for i in the foreach, but rather
than use the instance of i in the surrounding scope a local value is
used instead. The spec isn't clear on what should happen here, but I
would have guessed that the final value displayed would be 3, not 0.
Sean
More information about the Digitalmars-d
mailing list