Bird
0
0

Why does Ruby use elsif instead of else if in its if statements?

hard📝 Conceptual Q10 of 15
Ruby - Control Flow

Why does Ruby use elsif instead of else if in its if statements?

ATo avoid ambiguity and improve readability
BBecause <code>else if</code> is a syntax error in Ruby
CTo allow multiple else blocks
DTo enable nested if statements
Step-by-Step Solution
Solution:
  1. Step 1: Understand Ruby syntax design

    Ruby uses elsif as a single keyword to clearly separate multiple conditions.
  2. Step 2: Compare with other languages

    else if can cause ambiguity; Ruby's elsif improves clarity and readability.
  3. Final Answer:

    To avoid ambiguity and improve readability -> Option A
  4. Quick Check:

    elsif is for clarity in Ruby = B [OK]
Quick Trick: Elsif is one word for clarity in Ruby [OK]
Common Mistakes:
  • Thinking else if is invalid syntax
  • Believing multiple else blocks allowed
  • Confusing nested if with elsif

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes