File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About variables in Loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About variables in Loop" Watch "About variables in Loop" New topic

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!
Consider Paul's rocket mass heater.
subject: About variables in Loop
jQuery in Action, 3rd edition