Bird
0
0

Which of the following best describes the purpose of an else block in an if-else statement?

easy📝 Conceptual Q2 of 15
C - onditional Statements
Which of the following best describes the purpose of an else block in an if-else statement?
ATo execute code only when the <code>if</code> condition is true
BTo execute code when the <code>if</code> condition is false
CTo repeat the <code>if</code> condition
DTo stop the program
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of the if block

    The if block runs when the condition is true.
  2. Step 2: Understand the role of the else block

    The else block runs only when the if condition is false.
  3. Final Answer:

    To execute code when the if condition is false -> Option B
  4. Quick Check:

    else runs if if condition false [OK]
Quick Trick: else runs only if if condition is false [OK]
Common Mistakes:
  • Confusing else with if
  • Thinking else runs when condition is true
  • Believing else repeats the condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes