Questions: Else-If Chains and Multiple Conditions

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer writes the following grading logic: `if (score >= 60) { grade = 'D' } else if (score >= 70) { grade = 'C' } else if (score >= 80) { grade = 'B' } else if (score >= 90) { grade = 'A' }`. A student scores 93. What grade do they receive?

AA — because 93 >= 90 is the most specific matching condition
BD — because 93 >= 60 is true and is the first condition checked
CB — because the chain averages the matching conditions
DNo grade — the chain finds multiple matches and produces an error
Question 2 Multiple Choice

When should you choose an else-if chain over multiple independent if statements?

AAlways — else-if chains are strictly better than multiple if statements in every situation
BWhen the conditions are mutually exclusive and you want exactly one branch to execute per run
CWhen the conditions overlap and you want all matching branches to execute
DOnly when you have exactly three conditions — else-if chains with more conditions should use switch statements instead
Question 3 True / False

In an else-if chain, most conditions are evaluated most of the time the chain runs, regardless of which condition is true.

TTrue
FFalse
Question 4 True / False

The order in which conditions appear in an else-if chain has no effect on program correctness, as long as the conditions cover most cases.

TTrue
FFalse
Question 5 Short Answer

Explain why an else-if chain with poorly ordered conditions can silently produce wrong output instead of an error, and how you would detect or prevent this bug.

Think about your answer, then reveal below.