Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Operators and Expressions
What will this Ruby code print?
value = false
if value
  puts "Yes"
else
  puts "No"
end
AYes
Bfalse
CError
DNo
Step-by-Step Solution
Solution:
  1. Step 1: Check the value assigned

    The variable value is assigned false, which is falsy in Ruby.
  2. Step 2: Evaluate the if condition

    Since value is falsy, the else branch executes, printing "No".
  3. Final Answer:

    No -> Option D
  4. Quick Check:

    false is falsy = prints No [OK]
Quick Trick: false triggers else branch in if statements [OK]
Common Mistakes:
MISTAKES
  • Assuming false is truthy
  • Expecting 'Yes' output
  • Confusing false with nil

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes