A
Arne Vajhøj
Andreas said:A somewhat late resurrection of that thread...
Is your newsfeed late to show those articles
only now?
No - I am just behind reading.
Of course it is! The discussion wasn't about making it more
general, but about making a less general but (believed)more
common pattern syntactically simpler.
If one want to make a change then why not make it as general
as possible ?
It could be:
int[] myInts = new int[10];
{
for(int i = 0; i < myInts.length; i++) myInt = i * i + 1;
}
I dislike these nested blocks. They always make me look for
something in the previous lines, like a "for"/"if"/"while"/...
or a new SomeClass(...) (though without brackets and semicolon) -
only initializer blocks in classes are excepted, because they
happen in quite a different context.
In your example, it's even entirely unnecessary since the only
local variable in that block is already local to the "for".
And I think that is in many ways the essence.
If one want a loop, then just write a loop.
Arne