Recently i came across this question
int i = 10;
while (i++ <= 10) {
i++;
}
System.out.print(i);
The answer is 13 , can some please explain how is it 13?
This is one of the alternative ways I could wrap my head around this.
Let f(ref i)
be a function which takes in i by reference and increment it it's value by 1. So f(ref i) = i + 1
Now that we have f(ref i)
, the above code can be written as
int i = 10
while( (f(ref i) -1) <=10 )
{
f(ref i);
}
I would replace f(ref i)
with equivalent i values on its return and get the answer like
while(11 - 1 <= 10) {12}
while (13 -1 <= 10) -> break;
so i = 13.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With