I have gone through all the questions in this forum that are corresponding to this topic, and I felt to raise a different question as this question is not answered clearly. Here is my scenario: I have this class Test1:
public class Test1 { public static void main(String args[]) { int i=0, j=2; do { i= i+1; j--; } while(j>0); System.out.println(i); } } Now this is my question: a) If I replace the increment operation of 'i= i+1' with ++i, I get the desired output as
1 2 But if I replace the increment operation of 'i= i+1' with i++, I get the desired output as
0 0 I do understand the difference of using prefix and postfix operators in for loop, but why is the value not getting incremented at all in do-while loop?
i = i + 1;toi = i++;. If you don't know what's wrong with that you should go back and read all those questions again.i = i + 1withi++, literally?