int x = 3; while(x > 0) { System.out.println(x); x--; } /* Outputs 3 2 1 */ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

int x = 3; while(x > 0) { System.out.println(x); x--; } /* Outputs 3 2 1 */

in this code, shouldn't the value of x remain 3 when it is compared with 0 for the 2nd time as it is post decrement.

6th Aug 2018, 11:49 AM
Saurabh Negi
Saurabh Negi - avatar
1 Answer
0
on line x-- , it will be 3..post that line, x becomes 2..
6th Aug 2018, 12:06 PM
Ketan Lalcheta
Ketan Lalcheta - avatar