Programming-Idioms

History of Idiom 43 > diff from v15 to v16

Edit summary for version 16 :

Version 15

2015-08-23, 07:53:17

Version 16

2015-09-03, 17:28:03

Idiom #43 Break outer loop

Look for a negative value v in 2D integer matrix m. Print it and stop searching.

Idiom #43 Break outer loop

Look for a negative value v in 2D integer matrix m. Print it and stop searching.

Code
negative_value = catch :negative do
  matrix.each do |row|
    row.each do |value|
      throw :negative, value if value < 0
    end
  end
end

puts negative_value