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 Strange behaviour of 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 "Strange behaviour of "=" and "++"" Watch "Strange behaviour of "=" and "++"" New topic

Strange behaviour of "=" and "++"

Omer Haderi
Ranch Hand

Joined: Sep 27, 2006
Posts: 42

When I saw this snippet I was totally sure that the output was: 0 1

But it is: 0 0
if we remove line #2 then it will print zeros for ever.

I know that "=" has higher precedence so in line #1 the assignment take place first (so i = 0) and then the post increment (so i becomes 1) but the output is zero

does anyone have any hint ?

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
Try this link of this forum:

discussed before

Got it???


Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Search this forum for "i=i++" and you will find over a thousand topics discussing the same problem. Your answer is to be found there.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Omer Haderi
Ranch Hand

Joined: Sep 27, 2006
Posts: 42
I agree. Here's the link:
subject: Strange behaviour of "=" and "++"
jQuery in Action, 3rd edition