Bird
0
0

What does the elsif keyword do in Ruby?

easy📝 Conceptual Q11 of 15
Ruby - Control Flow

What does the elsif keyword do in Ruby?

AIt ends the <code>if</code> statement.
BIt runs code only if all previous conditions were true.
CIt checks another condition if the previous <code>if</code> or <code>elsif</code> was false.
DIt repeats the <code>if</code> block multiple times.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of elsif

    The elsif keyword is used to check another condition only if the previous if or elsif condition was false.
  2. Step 2: Compare with other options

    Options A, C, and D describe behaviors that do not match elsif. It does not end the statement, nor repeats code, nor runs only if all previous conditions were true.
  3. Final Answer:

    It checks another condition if the previous if or elsif was false. -> Option C
  4. Quick Check:

    elsif = check next condition [OK]
Quick Trick: Remember: elsif checks next condition if previous false [OK]
Common Mistakes:
  • Thinking elsif ends the if statement
  • Confusing elsif with else
  • Assuming elsif runs only if all previous are true

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes