Stopping an Iteration : break « Statement « Ruby






Stopping an Iteration


1.upto(10) do |x|
  puts x
  break if x == 3
end
# 1
# 2
# 3

 








Related examples in the same category

1.break ends the immediately enclosing loop.
2.Break out of a block
3.Break if
4.Read till 'quit'