user858642
user858642

Reputation: 197

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?

Upvotes: 5

Views: 11187

Answers (1)

Chris Ledet
Chris Ledet

Reputation: 11628

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

or

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

Upvotes: 11

Related Questions