Hi Meera, I've created a step-by-step guide of how this program gets executed and how it did prints 3 as the output. Hope this will help. Thanks.
Initialize: i=1
Step 1:
Enter do-while loop then increment i by 1: i=2
Step 2:
While statement will be execute, variable
b will be negated so it will be true: b=true
b is true so it will go to do-while body again
Step 3:
Enter do-while loop then increment i by 1: i=3
Step 4:
While statement will be execute, variable
b will be negated so it will be false: b=false
b is false so it will now exit do-while loop
Step 5:
Prints: 3