In C++ (and many other languages), operator &&
is a logical AND operator, which yelds true
only when both conditions are true
. If any of the conditions is false, the whole statement is false.
The code executes once because the do while
loop actually tests the condition at the end, after executing. If you would use a while
or for
loop here, the code inside wouldn’t be executed at all.
If you want to test if any of the conditions are true, use operator ||
instead, which is the logical OR operator. Here’re truth tables for both of the operators, taken from one of University of Florida sub-pages.
solved how many condition can be declared in do while? [closed]