I noticed something I hadn't realized before about for loops in Java.
For example an int and a long declared before the for loop may be initialized inside the initilization block.
int x;
long y;
for( x = 1, y = 2; x < 10 && y < 10; x++, y++) {
System.out.print(x + ", " + y );
}
However, those same variables will cause a compiler error if declared inside the initialization block.
//DOES NOT COMPILE.
for( int x = 1, long y = 2; x < 10 && y < 10; x++, y++) {
System.out.print(x + ", " + y );
}
Why is it that multiple variables declared before the initialization block can be of different data types, though variables declared inside the initialization block must be of the same type?