Can someone please explain the logic of this question, cannot seem to grasp the idea
What will be the result of attempting to compile and run the following program?
class TestClass
{
public static void main(
String args[])
{
boolean b = false;
int i = 1;
do
{
i++ ;
} while (b = !b);
System.out.println( i );
}
}
The answer is that it will print 3.
Guess that (b = !b) evaluates to (false = true), so therefore we go through another iteration because the condition is true, then I suppose it becomes (true = false) and exit the loop. Is this the correct reasoning?