Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ending ruby program if a given condition is met

Basically, I am just trying to stop the program from running the rest of the lines if a certain condition is met.

unless raw_information.first
  puts "No results were returned for that query"
  break
end

However, before the program even runs I get this error:

Invalid break compile error (SyntaxError)

What is the proper way to do this?

like image 855
user858642 Avatar asked Jul 24 '11 00:07

user858642


1 Answers

abort("No results were returned for that query") unless condition

or

unless condition
  abort("No results were returned for that query")
end
like image 177
Chris Ledet Avatar answered Nov 15 '22 04:11

Chris Ledet