| Author |
Please help me to figure out confusion with my program output.
|
rayan alex
Ranch Hand
Joined: Nov 25, 2012
Posts: 33
|
|
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
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
|
Yes, I think you have. I tried your code and got 3.
|
 |
rayan alex
Ranch Hand
Joined: Nov 25, 2012
Posts: 33
|
|
I just wanted to know whether i have followed correct path to get the output.
Thank you for you reply
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
|
Yes, you reasoned correctly. Well done.
|
 |
 |
|
|
subject: Please help me to figure out confusion with my program output.
|
|
|