+ 1
Question from challenges
Plz anyone explain me... https://i.postimg.cc/s2yZZrN8/Screenshot-20200828-090200.png
2 Réponses
+ 3
var x=6; and var y=0
while (x>0 &&y<6) here if both condition will be true then it will be run. here x=6 and y=0 then check while condition
while(6>0 &&0<6) which is true so loop will run in next line there is x-- here value of x will decrease by 1 so x =5 and after that y+=x means y=y+x =0+5 so 5 will be assign in y , y=5 after that loop will run again x was 5 and y is also 5
so while (5>0&&5<6) which is true so loop will go in inner part there is x-- so x will be 4 after next line y+=x means y=y+x here y is 5 and x is 4
so y=5+4 result will 9 and it will assign to y then loop will run again and now y is 9 and x is 4
while (4>0&&9<6) here Second condition is false so loop won't be run last value of y =9 will be final answer .
.......Thankyou.......
+ 1
Starting values x=6 and y=0
For first loop
X=5 and y=5
second loop
X=4 and y=9
As condition false(y<6)comes out and prints y=9