0
Someone kindly explain how we get to the answer,
I know it gives 3, but i would like to understand this piece of Code🙏🙏 https://code.sololearn.com/cpHtT14w7TBs/?ref=app
7 Respuestas
+ 2
A do while loop runs at least once and then keeps running as long as the condition is true. In this case the condition is false, so the loop runs only the one time.
Here you start with x=y=3. In the loop x is reduced by 3, so x=0. So y-x=3. Outside if the loop you have y-x again, but since x=0, y stays the same.
+ 2
Sorry there was a typo in my first answer: x=0 after the loop, not x=3. I corrected it above.
+ 1
Does x -= 3 mean x = 3-x or x=x-3 ? Simon Sauter
+ 1
x = x-3
+ 1
so the new value of x becomes y-(x-3) which is y-x+3 » 3-3+3 Simon Sauter
+ 1
No. The initial value of x is 3. Then it is reduced by 3 once. So at the end the value of x is 0.
Before the loop:
x = 3
y = 3
After the loop:
x = 0
y = 3
+ 1
Thank you very much 🙏
Well understood, step by Step👌 Simon Sauter