posted 4 years ago

Hi Guys.

Please help me to understand code given below. I tried to find the value for i. Few times i counted as 2. But finally i counted as 3 which is correct answer.

I just want to know, have i taken correct method to figure out the value for i.

This is how i counted.

b = false

i = 1

i++ increment i by 1. so new value of i is now 2.

b= !b means b's value assigned to true.

finally reach to while condition and its( value or b is) true. so loop continue.

increment i by 1. New value for i is 3

b= !b, Therefore b = false

Reach the while condition and its false. So go out from while loop and print 3.

Please help me to understand whether i have taken right path to figure out value of i.

Thank you in advance