0
I want to understand this: var x=0 while (x<6) { x ++; } document. write (x); output was 6
11 Réponses
+ 6
it says:
"as long as x<6, increment x".
so when x=5, the while condition is still true, so x is incremented to 6.
then, as x=6 the while condition becomes false and the loop stops.
after the loop, document.write(x) prints the value of x, which is 6.
+ 3
The code provided by you, will work in this manner, the loop will start from 0 and each time it will be increment because the statement given is true. When the loop will reach 5 < 6. It will be incremented for a last time making its value 6. 6 can't be greater than 6 therefore the statement will become false and it will stop the loop.
The value of x will be 6.
+ 2
ifl
Thank you
+ 1
ooooh... thank you "plenty"
+ 1
i was actually thinking it was going to write for all the values <6
so what code would show that
just to differientiate
+ 1
to print all values up to 6 (excluding 6):
while (x<6){
document.write(x);
x++;
}
+ 1
Donna
#winks for you
+ 1
Akash Pal
Thanks
0
Donna
that means for all the conditions that are true only the last to the false will be printed right
0
thank you
0
What’s the output of this code?
var x = 0;
while(x<6) {
x++;
}
document.write(x);
output is 6