Bird
0
0

What does the Ruby unless keyword do?

easy📝 Conceptual Q11 of 15
Ruby - Control Flow
What does the Ruby unless keyword do?
ARuns the code block regardless of the condition
BRuns the code block only if the condition is true
CRuns the code block only if the condition is false
DRuns the code block twice if the condition is false
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of unless

    The unless keyword runs code only when the condition is false, opposite of if.
  2. Step 2: Compare with other options

    Options B and C describe if or unconditional execution, D is incorrect behavior.
  3. Final Answer:

    Runs the code block only if the condition is false -> Option C
  4. Quick Check:

    unless = run if false [OK]
Quick Trick: Think: unless means "if NOT" the condition [OK]
Common Mistakes:
MISTAKES
  • Confusing unless with if
  • Thinking unless runs when condition is true
  • Assuming unless runs code twice

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes