0

got confused with JSChallange, decrement in WhileLoop

i got this question where var a; var b = 0; a = 20; a = --a; while(a > a--){ b++; } document.write(b); the result that i got is 0, why? is the 'b' not being processed by the while loop? or its just a trap question? Or is it because a>a-- is 19 > 19 which is returned false so that the looping do not runing thus the 'b' is back to the first value? Am I clear enough to describe my question? I'm afraid you don't understand with what I'm trying to ask

7th Oct 2021, 10:59 AM
KepoLu
KepoLu - avatar
4 ответов
0
I would assume it's because 19 == 19. Since it's a post decrement, the variable 'a' won't be affected until after, so you got it. It just won't trigger the while loop
7th Oct 2021, 11:10 AM
Slick
Slick - avatar
+ 1
oh ok i understand now, tysm for your explanation
7th Oct 2021, 12:53 PM
KepoLu
KepoLu - avatar
0
Slick so its true that the WHILE looping do not asign the b++ to the 'b' because the condition that the WHILE meet is 'false' And the value of 'b' is still 0.
7th Oct 2021, 11:15 AM
KepoLu
KepoLu - avatar
7th Oct 2021, 11:52 AM
Slick
Slick - avatar