Tsallaka zuwa abun ciki
Justice Tech School

Ruby If, Unless and Ternary

if and elsif choose branches, unless runs when a condition is false, and statement modifiers put the condition after.

Example
score = 72
if score >= 85 then puts "A"
elsif score >= 70 then puts "B"
else puts "C"
end
puts "ok" unless score < 50
puts "high" if score > 60
puts score > 50 ? "pass" : "fail"

Result

B
ok
high
pass

Exercise

Run when false.

puts "x"  done

Quiz Test

What does unless do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.