Programming-Idioms

History of Idiom 43 > diff from v7 to v8

Edit summary for version 8 :

Version 7

2015-08-01, 17:37:45

Version 8

2015-08-01, 17:39:13

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
OUTER:
for my $i (0 .. $#m) {
   for $j (0 .. $#{$m[$i]}) {
      if ($m[$i][$j] < 0) {
         print "Negative value found: $v\n";
         last OUTER;
      }
   }
}
Code
OUTER:
for my $row (@m) {
   for $v (@$row) {
      next unless $v < 0;
      print "Negative value found: $v\n";
      last OUTER;
   }
}