User Tools

Site Tools


Sidebar

Writing /opt/bitnami/dokuwiki/data/meta/git/delete-tag.meta failed
Unable to save metadata file. Hint: disk full; file permissions; safe_mode setting.

Go Back

Contact
Recent Changes
Sitemap
go:labeled_jump_statements

Labeled Jump Statements in Golang

Break Statement

https://golang.org/ref/spec#Break_statements

A “break” statement terminates execution of the innermost “for”, “switch”, or “select” statement within the same function.

BreakStmt = "break" [ Label ] .

If there is a label, it must be that of an enclosing “for”, “switch”, or “select” statement, and that is the one whose execution terminates.

OuterLoop:
	for i = 0; i < n; i++ {
		for j = 0; j < m; j++ {
			switch a[i][j] {
			case nil:
				state = Error
				break OuterLoop
			case item:
				state = Found
				break OuterLoop
			}
		}
	}

Continue statements

https://golang.org/ref/spec#Continue_statements

A “continue” statement begins the next iteration of the innermost “for” loop at its post statement. The “for” loop must be within the same function.

ContinueStmt = "continue" [ Label ] .

If there is a label, it must be that of an enclosing “for” statement, and that is the one whose execution advances.

RowLoop:
	for y, row := range rows {
		for x, data := range row {
			if data == endOfRow {
				continue RowLoop
			}
			row[x] = data + bias(x, y)
		}
	}

Goto statements

https://golang.org/ref/spec#Goto_statements

A “goto” statement transfers control to the statement with the corresponding label within the same function.

GotoStmt = "goto" Label .
goto Error
go/labeled_jump_statements.txt · Last modified: 2020/04/08 16:19 by whtsky