0
Why did this code output 60 and not 50?
var x =10 x*= 2 while (x<30) { x+= 5 y=x } alert(y+x); I want to know in details if possible
4 Answers
+ 4
20<30 is true so now inside while x=x+5 so x becomes 25 and y is also 25 since y=x.
Now 25<30 is again true so now inside while x=x+5 so x becomes 30 and y is also 30 since y=x.
Now 30<30 condition fails and the loop is terminated. Now both x and y are 30 so x+y=60.
+ 2
So the loop doesn't stop unless the certain condition is achieved. Now I know where I did wrong, I looped once which gave the output 50.
Avinesh thanks.
+ 1
Because the loop broke when x = 30 and when y = 30