Unless help


I have a question regarding unless. I don't understand why the example used does not need 'end' at the end of it:

problem = false
print "good to go!" unless problem


should we not have to add end at the end of this?
When creating my own unless statement I had to use end or I got an error:

a = 10
b = 100

unless a == b
print "b is greater than a"


@afrover you only need an "end" statement when your code spans multiple lines. With "if" and "unless" statements, it's possible to write them on one line like you stated in your first example. Because the code is written on one line, the Ruby interpreter knows when the statement is complete because a new line is created. I hope this helps!


hi i have a question please with unless too..

hungry = false

puts "I'm writing Ruby programs!"

puts "Time to eat!"

i really donĀ“t understand or i need help. thanks!


i also don't understand this one