Given that you can use a 'for' over a 'while' any time and, AFAIAA,
without any penalties,
Without penalties? What are those two semicolons, then?
I don't find that annoying at all. I prefer the 'for' anyway.
Fair enough. Personally, i find the for loop syntax really clumsy.
This:
int place ;
while ((place = s.indexOf(x)) >= 0 ) ...
Can be written:
for (int place; (place = s.indexOf(x)) >= 0
...
But that looks hell of ugly to me - it's got a repetition of the variable
name and two completely pointless semicolons.
This:
while ((int place = s.indexOf(x)) >= 0) ...
Would be much nicer. Although then you'd have to allow declarations inside
expressions, and the world would rapidly go mad. This:
this.foo = someBoolean ? (int bar = 23) : ((String bar = "baz").hashCode()) ;
Would be fun. I guess the rule would be that any statement involving a
declaration inside an expression gets rewritten as a block comprising the
declaration followed by the expression with the declaration changed to an
assignment. So Roedy's example would become:
{
int place ;
while ((place = s.indexOf(x)) >= 0 ) ...
}
Exactly as desired, and the troublemaking example would become:
{
int bar ;
String bar ;
this.foo = someBoolean ? (bar = 23) : ((bar = "baz").hashCode()) ;
}
Which would then fail to compile, because of the conflicting decarations
of bar.
You'd have to be a bit clearer about scope, though. Clearly, this:
int foo = (int bar = 23) + 1 ;
baz(foo) ;
Couldn't be rewritten to this:
{
int bar ;
int foo = (bar = 23) + 1 ;
}
baz(foo) ;
Because it screws up the scope of foo. It'd have to be:
int foo ;
{
int bar ;
foo = (bar = 23) + 1 ;
}
baz(foo) ;
There are doubtless other traps.
tom