Programming-Idioms

History of Idiom 43 > diff from v8 to v9

Edit summary for version 9 :

Version 8

2015-08-01, 17:39:13

Version 9

2015-08-01, 17:39:47

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