Created
August 16, 2021 20:37
-
-
Save percybolmer/a8d1eef158c200128c9ed1cb64566259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++ { | |
// printInteger will try to goto to exit, which will not work | |
printInteger(i) | |
} | |
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") | |
} | |
func printInteger(i int) { | |
fmt.Printf("Index: %d\n", i) | |
if i == 5 { | |
// When i is 5, lets exit by using goto | |
goto exit | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment