Programming-Idioms

History of Idiom 43 > diff from v29 to v30

Edit summary for version 30 :
[Haskell] Just added spaces for more idiomatic formatting

Version 29

2016-02-16, 19:41:59

Version 30

2016-02-18, 16:57:59

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
(print . head . filter (<0) . concat) m
Code
(print . head . filter (<0) . concat) m
Comments bubble
Haskell's lazy evaluator takes care of breaking all looping when no more searching is needed beyond the first found negative
Comments bubble
Haskell's lazy evaluator takes care of breaking all looping when no more searching is needed beyond the first found negative
Code
mainloop:
	for i, line := range m {
		for _, v := range line {
			if v < 0 {
				fmt.Println(v)
				break mainloop
			}
		}
	}
Code
mainloop:
	for i, line := range m {
		for _, v := range line {
			if v < 0 {
				fmt.Println(v)
				break mainloop
			}
		}
	}
Comments bubble
mainloop is a label used to refer to the outer loop.
Comments bubble
mainloop is a label used to refer to the outer loop.
Doc URL
https://golang.org/ref/spec#Break_statements
Doc URL
https://golang.org/ref/spec#Break_statements
Demo URL
http://play.golang.org/p/uthiN89xX4
Demo URL
http://play.golang.org/p/uthiN89xX4