Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Control Flow
What is the output of this Ruby code?
count = 3
unless count > 5
  puts 'Count is small'
else
  puts 'Count is large'
end
ACount is small
BCount is large
CNo output
DSyntaxError
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition count > 5

    Given count = 3, the condition 3 > 5 is false.
  2. Step 2: Apply unless logic

    unless runs the first block if condition is false, so it prints 'Count is small'.
  3. Final Answer:

    Count is small -> Option A
  4. Quick Check:

    Condition false -> unless runs first block [OK]
Quick Trick: Remember unless runs when condition is false [OK]
Common Mistakes:
  • Thinking unless runs when condition is true
  • Confusing else block execution
  • Expecting no output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes