This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
As an aside, I feel strongly that pre-increment (++i) works in a much more intutive way than post-increment (i++), and blame lots of textbook and programming standards writers (starting with Kernighan and Richie) for using post-increment so much where it is not needed. Personally, I always use pre-increment unless I have a real need for the special behaviour of post-increment, and I try and teach my development teams the same habit.
when u say int i; i = i++; System.out.println(i) The output is 0 because in int i ; i is set to 0 then when u say i = i + + this means increment the value of i after performing the task assigned in this case the task is System.out.println(i) hence o if u put it in a loop the next time i = i ++ is executed it will print 1
Joined: Nov 08, 2000
Yeah, I was always taught post-increment, and now I always use it unless I have a reason not to. I suppose pre-increment is more intuative, but you tend to get into a 'style', don't you. I think maybe people teach i++ because it's more like i=i+1. Or maybe it just rolls of the tongue easier.
Joined: Jan 07, 1999
Depends how you say it. I find "increment i" to be more sensible to say that "i increment" (which usually begs the question "you increment what?")