0

[Answered]While loop -- very strange flow

All inside https://code.sololearn.com/cBBB4PDNam1W/?ref=app

31st Mar 2017, 7:11 PM
Alex Snaidars
Alex Snaidars - avatar
2 Answers
+ 1
int a=3, b=4; while (++a==b--){} System.out.println(a+" "+b); first iteration: ++a==b-- ==> 4==4 (True) ==> a=4,b=3 Second itration: ++a==b-- ==> 5==3 (False) ==> a=5,b=2 output : "5 2" remember ++a==5 is to increment a first then check, a++==5 is to check a first then increment a.
31st Mar 2017, 7:22 PM
Moataz El-Ibiary
Moataz El-Ibiary - avatar
0
So basically its 1) satisfying the condition and doing the math hence going on loop 2) not satisfying the condition and doing the math, exiting the loop
31st Mar 2017, 7:38 PM
Alex Snaidars
Alex Snaidars - avatar