+ 8
Can anyone explain the result of this while loop?
var i = 0; while(i<6){ i++; } document.write(i);
20 Respostas
+ 32
The output is 6.
The while loop runs for the values of i from 0 to 5. When it is 5, i is incremented to 6. Then the condition of the while loop is false (6<6 is false) and the loop stops. Now i is printed with it's current value which is still 6.
[Edit] I'm too late, finished typing after the others ^^
+ 16
this loop will continue till i is < 6.
First time :- i=1
2nd :- i=2
3rd :- i=3
4 th:- i=4
5th :- i=5
Here ,now i is still less than 6, hence,
6th:- i=6, Now i is = 6 but not less than 6 ,Hence output is 6
+ 4
it will repeat post increment on i until i equals 6
at that point the while loop stops and the value of i (6) is printed.
+ 4
Variable i is 0 and while i is smaller than 6, the looping will continue.
1. Because i = 0 and the condition 0 < 6 is true, program will execute the code inside the looping.
2.Inside the looping:
i++ is similar to i = i + 1. The variable i will be incremented by 1 everytime it is looping.
3. after i=5 it won't stop because it is still smaller than 6 and the program will execute the code inside looping. so i+1 is 6.
4. Because 6<6 condition return false, the looping stop.
Sorry for my bad english. :)
+ 2
The result is 6
i=0 the program verify, 0<6, i++=1
i=1, 1<6, i++=2
i=2, 2<6, i++=3
i=3, 3<6, i++=4
i=4, 4<6, i++=5
i=5, 5<6, i++=6
i=6, 6=6, it's not less, the loop end there, and the program print 6.
+ 2
on the last iteration, i is equal 5 and i will be increased by one to 6. now: 6<6 isn't true anymore, so the while loop will break. now i equal 6, and 6 will be printed.
+ 1
I know there are plenty replys already but the output is 5 beacause you put i<6, it would output six if you put i<=6 I hoped this helped :D
+ 1
the loop increase until 6 remember 0 is the first position and start the loop 0+1
0
Loop continues until i = 6, next the code write i (=6).
0
Answer will be 6!
0
I=6
0
loop goes till i=5 then get terminated
0
hallo
- 1
i think it adds up until i<6 becomes invalid
- 2
output is
1
2
3
4
5
.and there no 6 cuz the code is <6
- 2
jyoti can i contact u pls......my email is yugalpathak2012@gmail.com
- 3
The final output of this loop will be 5.
Every time the loop runs, i is incremented by 1 (i++)
The loop runs until i is 5 because (i<6) is true as long as i is 5 or less.
- 3
6
- 3
You need to put <=6 if you don't want enter in a loop.
- 5
6