This week's book giveaway is in the Other Languages forum.We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!

rayan alex
Ranch Hand
Posts: 33
1

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.

Campbell Ritchie
Sheriff
Posts: 50266
80
• 1
Yes, I think you have. I tried your code and got 3.

rayan alex
Ranch Hand
Posts: 33
1
I just wanted to know whether i have followed correct path to get the output.