| Author |
About variables in Loop
|
Andry Dub
Ranch Hand
Joined: Nov 06, 2007
Posts: 43
|
|
What is wrong with my code? for(int m=0,n=0;m<5;(m++)++) { System.out.print(m + " "); }
|
Java is my love
|
 |
Kelvin Chenhao Lim
Ranch Hand
Joined: Oct 20, 2007
Posts: 513
|
|
Hi Andry, "(m++)++" is not valid Java syntax, even when it's not part of a loop. The ++ operator must always operate on an assignable variable (or what people sometimes call an "lvalue"). "m++" is not an assignable variable, which means you cannot write a statement like "m++ = 5". "m++" by itself is fine, but this evaluates to an integer value--and you cannot use ++ on a raw integer value (i.e. you can't write "2++"). To achieve what you seem to be trying to do, use something like this instead:
|
SCJP 5.0
|
 |
Andry Dub
Ranch Hand
Joined: Nov 06, 2007
Posts: 43
|
|
|
Thank you very much for your interesting reply!
|
 |
 |
|
|
subject: About variables in Loop
|
|
|