0
How this code ran ??
Whats the output of this code var x = 0; While ( x < 6 ) { x++ ; } document.writs(x); Its given 6 !!! Why ?
1 Answer
+ 1
Because loop runs to the time the condition is false at start of the iteration
x = 0
x<6 //true
x++
x<6 //true x=1
x++
x<6 //true x=2
x++
x<6 //true x=3
x++
x<6 //true x=4
x++
x<6 //true x=5
x++ // x is 6 when the next line starts (or the condition of the loop is checking) and loop will end when it will check the condition again
x<6 //false x=6