How to break double statement?
a = 1
b = 2
c = 3
if a == 1
if b == 2
c = 5
d = 6
break
end
end
puts c
puts d
Output
loop.rb:9: Invalid break
loop.rb: compile error (SyntaxError)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t break from inside an
if, you can only break from inside loops and blocks.If what you’re asking is how to break from two nested loops, you can use
catchin combination withthrow—these are not the same as try and catch in other languages.Of course, you can always just set a flag or some such to tell the outer loop that it should break too.