Use if statement to check zero : zero « Number « Ruby






Use if statement to check zero


op = 0

if !op.zero? # not a zero?
  puts 12 / op
else
  puts "Can't divide by zero."
end

op = 2

if op.nonzero? # is it nonzero?
  puts 12 / op
else
  puts "Can't divide by zero."
end

 








Related examples in the same category

1.if a value is a zero or not.