+ 12

While and postfix/prefix

var a = 20; var b = 0; a = --a; while(a>a--){ b++; } document.write(b); //outputs 0. I don't understand lines 3-5. Can anyone help? Thank you

10th Mar 2017, 8:03 PM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar
3 odpowiedzi
+ 7
Line 3 decrements a. Line 4 is "while a is greater than a"; then it decrements a (post, not pre) So it will find that a !> a, so b won't be incremented. Therefore b stays at 0 and then is printed.
10th Mar 2017, 8:08 PM
J.G.
J.G. - avatar
+ 11
very helpful thank you
10th Mar 2017, 8:19 PM
‎‏‎‏‎Joe
‎‏‎‏‎Joe - avatar