Why is such result ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why is such result ?

var x=0; var y=0; do{ y++; } while(x<0) document.write(y); x<0 this false. so do function not working and must y=0 . but output y=1

20th Sep 2016, 8:27 PM
Sezgin GÜL
Sezgin GÜL - avatar
2 Answers
+ 2
/*U wrong Bro... "do while " Loop will execute your statement in do block for first and it check ur condition for second...I pointed with two step in lower program you gave...*/ var x=0; var y=0; do{ y++; //First Step- In this state the condition isn't check yet and it'll change y value to 1. } while(x<0) */Second Step-Checked the condition and it failed. So, It won't execute the statement between do block for second time and looping is over...*/ document.write(y);
20th Sep 2016, 9:11 PM
Hein Htut Aung
+ 1
now İ understand. thank you.
20th Sep 2016, 10:35 PM
Sezgin GÜL
Sezgin GÜL - avatar