+ 1
Why do I get the number 5 as a result, if the condition says it is less than 5?
3 Antworten
+ 1
When i=5 condition 5<5 false.
0
but why is the number 5 printed if when condition 5 < 5 is evaluated the code inside should no longer be executed because it is false
0
You are not printing value inside loop.
You are printing it after outside loop..
2nd loop don't perform anything...
edit:
cesar lopez run this code and see output:
//======== case 1========
var i= 0
while(i < 5){ //false when I=5,
++i
document.write("inside loop :"+i+"<br>");
}
//Resut 5
document.write("outside after loop :"+i+"<br>");
//======== case 2========
while(i < 5){ //initially false
i++
document.write("inside 2nd : "+i)
}
// Result 5
document.write("finally outside :"+i+"<br>");