Programming-Idioms

History of Idiom 43 > diff from v30 to v31

Edit summary for version 31 :
New PHP implementation by user [nvius]

Version 30

2016-02-18, 16:57:59

Version 31

2016-02-19, 21:39:41

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
for ($y = 0; $y < count($m); $y++) {
    for ($x = 0; $x < count($m[$y]); $x++) {
        if ($m[$y][$x] == $v) {
            break 2;
        }
    }
}
Doc URL
http://php.net/manual/en/control-structures.break.php