4.4. Preview Questions#
Complete these questions before class to prepare for the chapter. Use the dropdowns to check your answers.
4.4.1. True or False#
1. An else clause is required for every if statement.
Answer
False — else is optional; if alone is valid.
2. The && operator returns true only when both conditions are true.
Answer
True — && is logical AND — both sides must be true.
3. A switch statement in C# can only test integer values.
Answer
False — C# switch works with int, string, enum, and more.
4. The ! operator negates a boolean value.
Answer
True — !true evaluates to false and vice versa.
5. Compound boolean expressions can always replace nested if statements.
Answer
True — Nested conditions can be flattened using && and ||.
4.4.2. Multiple Choice#
1. Which operator represents logical OR in C#?
a) |
b) ||
c) OR
d) or
Answer
b) || — || is the short-circuit logical OR; | is the bitwise OR.
2. In a switch statement, which keyword exits the current case?
a) exit
b) end
c) break
d) stop
Answer
c) break — break prevents fall-through to the next case.
3. Which expression is true when x = 5?
a) x > 10 && x < 3
b) x > 3 && x < 10
c) x > 10 || x < 3
d) !(x == 5)
Answer
b) x > 3 && x < 10 — 5 > 3 is true AND 5 < 10 is true, so the whole expression is true.
4. What does condition ? a : b return when condition is false?
a) condition
b) a
c) b
d) null
Answer
c) b — The ternary operator returns b on false.
5. Which statement best describes an if-else if-else chain?
a) All branches always execute
b) Only the first matching branch executes
c) The last branch always executes
d) Branches execute in parallel
Answer
b) Only the first matching branch executes — Execution stops at the first condition that evaluates to true.
Footnotes