
10 May
2005
10 May
'05
10:21 p.m.
But users might reasonably expect this:
int i = 0; for( i : vect ) { } // maybe use i here
My feeling is the above should be a compiler warning, that the "i" in the for loop is hiding the outer "i".
to use the pre-declared i as a loop variable instead of introducing a new variable. That's an important use case, and some allowance should be made for it in the chosen syntax.
Wouldn't someone wanting to do something "clever" like that fall back to using a normal for() or while() loop? I thought for(i:vect){} is a convenience function to save typing and make code clearer; can it do something a while() loop cannot? Darren