When you have a construct
1 2 3 4
|
do
{
} while (condition)
|
The instructions in the do block are executed
After the end of the do block, the condition is tested
As long as the condition is true the do block is executed again, and the condition tested again.
This will continue until the condition is false.
The condition can be any expression. If the expression yields false or zero, then the condition is false.
Any other result and the condition is true.
invalid_choice is of type bool, which means it can only have one of two values, either true or false.
Before the switch, invalid_choice is set to false. Inside the switch block, if the default case is executed, then invalid_choice is set to true. When it is tested after the block the result is therefore true- that means the do block will be executed again.
If any of the valid choices are picked, then nothing changes the value of invalid_choice from false, so when it is tested after the do block it is found false, and the do-while loop ends.
Check out the do-while section on this page:
http://www.cplusplus.com/doc/tutorial/control/