What does a Boolean expression produce in C++?
A Boolean expression produces a result interpreted as either true or false. C++ contextually converts conditions to bool.
Study 03 Conditional Control Structures with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What does a Boolean expression produce in C++?
A Boolean expression produces a result interpreted as either true or false. C++ contextually converts conditions to bool.
Which operator tests equality in C++?
Use == to compare values. A single = assigns a value, so it should not replace == in an equality test.
What is short-circuit evaluation?
For A && B, C++ skips B when A is false. For A || B, it skips B when A is true.
What do &&, ||, and ! mean?
Use && when both conditions must be true; use || when at least one condition must be true; use ! to invert a Boolean value.
When does an if body execute?
An if statement executes its controlled statement or block only when its condition is true.
When does an else clause execute?
The else clause runs when the associated if condition is false.
Which if does an else belong to?
An else belongs to the nearest preceding unmatched if in the same statement structure. Braces make the intended association explicit.
How does an else-if chain choose a branch?
An else-if chain checks conditions in order, executes the block for the first true condition, and skips all later branches.
What is a nested condition?
Nesting places one conditional statement inside another. It is useful when a second decision should occur only after a first requirement succeeds.
When is switch appropriate?
A switch compares one expression with several constant case values, usually using an integral or enumeration value.
What does break do in a switch?
A break exits the switch. Without it, execution continues into the next case; this is called fallthrough.
Why might several case labels share one block?
Intentional fallthrough lets multiple case values share one action, such as cases 6, 7, and 8 sharing a summer branch.