Answer the question
In order to leave comments, you need to log in
Why can't Java initialize variables of different types in a for clause?
?Why can't you create a structure like
for(int i = 1, double j = 1.0; i<=10, j<=9.99; i++, j++) {}
for(double i = 1.0, j = 2.8; i<=10.0 || j<=9.99; i++, j+=0.38) {}
Answer the question
In order to leave comments, you need to log in
Probably because you can't initialize variables this way outside of the for loop.
You can't write:
int a, double d
But you can like this:
int a; double d;
And in the cycle, the semicolon will already be the division of the block.
If you really feel like iterating over two variables, you can get around this like this:
int i = 1;
double j = 1.0;
for(; i<=10, j<=9.99; i++, j++) {}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question