aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About variables in Loop" Watch "About variables in Loop" New topic
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About variables in Loop
 
Similar Threads
simple frame, gridbag
Unary Operator
Operator precedence
while(m++
IncrementOperator