Programming-Idioms

History of Idiom 43 > diff from v24 to v25

Edit summary for version 25 :
[Go] +DocURL

Version 24

2015-12-18, 03:27:45

Version 25

2015-12-30, 23:34:05

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
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
Demo URL
http://play.golang.org/p/uthiN89xX4
Demo URL
http://play.golang.org/p/uthiN89xX4