Skip to content
Justice Tech School

Numbers and Conditions

Integers and floats behave as in most languages, and 7 / 2 is 3 for integers. if, elsif, else and unless choose branches, and case handles many options. Only nil and false are falsy.

Example
puts 7 / 2, 7.0 / 2, 7 % 2, 2 ** 10
score = 72
if score >= 85
  puts "Distinction"
elsif score >= 70
  puts "Pass"
else
  puts "Retake"
end
puts "ok" unless score < 50
case score
when 0..49 then puts "low"
when 50..100 then puts "fine"
end

Result

3
3.5
1
1024
Pass
ok
fine

Exercise

Second condition keyword.

if a
else b
end

Quiz Test

Which values are falsy in Ruby?

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