Bird
0
0

What will this Ruby code output?

medium📝 Predict Output Q5 of 15
Ruby - Control Flow
What will this Ruby code output?
num = 10
if num > 5 then puts 'Greater' else puts 'Smaller' end
ANo output
BSmaller
CSyntax Error
DGreater
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition

    num is 10, which is greater than 5, so the condition is true.
  2. Step 2: Determine which branch runs

    Since condition is true, it executes puts 'Greater'.
  3. Final Answer:

    Greater -> Option D
  4. Quick Check:

    Simple if true branch output = A [OK]
Quick Trick: if runs true branch, else runs otherwise [OK]
Common Mistakes:
  • Confusing true and false branches
  • Thinking then causes error
  • Expecting no output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes