Logo

Programming-Idioms

History of Idiom 43 > diff from v23 to v24

Edit summary for version 24 by :
New Erlang implementation by user [elbrujohalcon]

Version 23

2015-11-30, 12:37:28

Version 24

2015-12-18, 03:27:45

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
find_negative_in([]) -> undefined;
find_negative_in([Row|Rows]) -> find_negative_in(Row, Rows).

find_negative_in([], Rows) -> find_negative_in(Rows);
find_negative_in([Pos|Values], Rows) when Pos >= 0 ->
	find_negative_in(Values, Rows);
find_negative_in([Neg|_], _) -> Neg.
Comments bubble
Assuming the matrix is implemented as a list of lists.
We just use a recursive function that instead of printing the value, just returns it.
Demo URL
http://tryerl.seriyps.ru/#id=04f3