Break out of a block : break « Statement « Ruby






Break out of a block


def oscillator
  x = 1
  while true
    yield x
    x *= -2
  end
end
oscillator { |x| puts x; break if x.abs > 50; }

 








Related examples in the same category

1.break ends the immediately enclosing loop.
2.Stopping an Iteration
3.Break if
4.Read till 'quit'