Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 16, 2021 20:31
Show Gist options
  • Save percybolmer/353b076f0e2c0eb9eb91f39ecae38dbe to your computer and use it in GitHub Desktop.
Save percybolmer/353b076f0e2c0eb9eb91f39ecae38dbe to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, Reader! Your learning about 'goto' statement")
// We create a for loop which runs until i is 10
for i := 0; i < 10; i++ {
fmt.Printf("Index: %d\n", i)
if i == 5 {
// When i is 5, lets exit by using goto
goto exit
}
}
fmt.Println("Skip this line here")
// Create the exit label and insert code that should be executed when triggered
exit:
fmt.Println("We are now exiting the program")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment