0

JS while... do... question

Why will this loop run only once? To me, it should do 10 times... x=0; do{ x++; }while(x>=10);

11th Apr 2017, 11:49 AM
Simon Nadolski
Simon Nadolski - avatar
2 Answers
+ 8
x never goes above 2 your condition says while x is greater or equal to 10 x starts as 0 the loop is executed once, incrementing x to 1 and then exits when the condition is not met
11th Apr 2017, 12:05 PM
Burey
Burey - avatar
+ 1
yes. of course. it's so obvious. while executes as long as it's true. here it's never true and that's what confused me. thanks.
11th Apr 2017, 12:40 PM
Simon Nadolski
Simon Nadolski - avatar