+ 1

Why do I get the number 5 as a result, if the condition says it is less than 5?

https://code.sololearn.com/Ww61BM8LVfSE/?ref=app

20th Apr 2022, 12:48 PM
cesar lopez
cesar lopez - avatar
3 Respostas
+ 1
When i=5 condition 5<5 false.
20th Apr 2022, 1:01 PM
Jayakrishna 🇮🇳
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
20th Apr 2022, 1:48 PM
cesar lopez
cesar lopez - avatar
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>");
20th Apr 2022, 2:30 PM
Jayakrishna 🇮🇳