Of course, a do loop always permits the first iteration, so i becomes 2.
"while (b = !b)" is tricky. It contains an assignment expression, not a conditional expression.
If an assignment operator (=) is used in an expression, the value of the right hand side of = becomes the result of the operation.
In this case, "b = !b" takes b, which has the value false, negates it, giving the value true, and stores true in b. However, the value true is also used as the value of the expression "a = !b", so "while(b = !b)" is true and the second iteration of the do loop is permitted. Now i becomes 3.
Now, b is true, so b becomes false and while("b = !b)" is false. So the do loop falls through and i remains 3 and is printed as 3. [ November 22, 2004: Message edited by: Mike Gershman ]
SCJP 1.4, SCWCD in process
Joined: Sep 20, 2004
El Perfecto !
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com