Skip to content

Instantly share code, notes, and snippets.

@eduncan911

eduncan911/main.go

Created Jun 9, 2016
Embed
What would you like to do?
Labels in GoLang
package main
import "fmt"
/*
Here's a use of labels in Go to continue a for loop
from within another for and within a switch case.
*/
func main() {
foo := []string{"a", "b", "c", "d", "e", "f", "g"}
bar := []string{"b", "d", "f"}
fooloop:
for _, v := range foo {
for _, v2 := range bar {
switch {
case v == v2:
continue fooloop
}
}
fmt.Println(v)
}
}
/*
output$ go run main.go
a
c
e
g
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment