Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 332 Bytes

File metadata and controls

24 lines (20 loc) · 332 Bytes

break

You can use break to break out of a while loop:

a = 2
while (a += 1) < 20
  if a == 10
    break # goes to 'puts a'
  end
end
puts a #=> 10

break can also take a parameter which will then be the value that gets returned:

def foo
  loop do
    break "bar"
  end
end
puts foo #=> "bar"