Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Php

Idiom #43 Break outer loop

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

Control flow jumping forward after the end of the outermost loop
for ($y = 0; $y < count($m); $y++) {
    for ($x = 0; $x < count($m[$y]); $x++) {
        if ($m[$y][$x] == $v) {
            break 2;
        }
    }
}
Outer_loop:
for A in M'Range (1) loop
   Inner_Loop:
   for B in M'Range (2) loop
      if M (A, B) < 0 then
         Put_Line (M (A, B)'Image);
         exit Outer_Loop;
      end if;
   end loop Inner_Loop;
end loop Outer_Loop;

New implementation...
< >
programming-idioms.org