Skip to content

Instantly share code, notes, and snippets.

@eduncan911
Created June 9, 2016 19:56
Show Gist options
  • Select an option

  • Save eduncan911/a422423f5a42f1825f5ededf9610f1cd to your computer and use it in GitHub Desktop.

Select an option

Save eduncan911/a422423f5a42f1825f5ededf9610f1cd to your computer and use it in GitHub Desktop.

Revisions

  1. eduncan911 created this gist Jun 9, 2016.
    32 changes: 32 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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
    */