Bird
0
0

Which of the following is a correct use of unless for a negated condition?

easy📝 Conceptual Q2 of 15
Ruby - Control Flow
Which of the following is a correct use of unless for a negated condition?
Aunless x > 10 puts 'Not ten' end
Bunless x != 10 puts 'Not ten' end
Cunless x == 10 puts 'Not ten' end
Dunless x < 10 puts 'Not ten' end
Step-by-Step Solution
Solution:
  1. Step 1: Identify negated condition

    We want to run code when x is NOT 10, so condition is x == 10 false.
  2. Step 2: Check each option

    unless x == 10 puts 'Not ten' end runs when x is not 10 (x == 10 is false). Others do not match this logic.
  3. Final Answer:

    unless x == 10\n puts 'Not ten'\nend -> Option C
  4. Quick Check:

    unless with equality negates condition [OK]
Quick Trick: Use unless with positive condition to check negation [OK]
Common Mistakes:
MISTAKES
  • Using unless with != instead of ==
  • Confusing > and < in conditions
  • Misreading negation logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes