Home >Backend Development >Golang >What is the usage of goto in go language?
Usage of goto in go language: [if n >10 {goto label}]. The goto statement in Go language can unconditionally branch to a specified line in the program. The goto statement is usually used in conjunction with conditional statements to implement functions such as conditional transfer and jumping out of loop bodies.
The operating environment of this article: windows10 system, Go 1.11.2, thinkpad t480 computer.
1. Basic introduction to goto
The goto statement of Go language can unconditionally transfer to a specified line in the program.
The goto statement is often used with conditional statements. It can be used to implement conditional transfer, jump out of loops and other functions.
In Go programming, it is generally not recommended to use goto statements to avoid confusing the program flow and making it difficult to understand and debug the program
2. goto’s flow chart
2. Case
package main import( "fmt" ) func main(){ var n = 20 if n >10 { goto lable } fmt.Println("不走这里") lable: fmt.Println("走这里") } //结果输出:走这里
Related recommendations: golang tutorial
The above is the detailed content of What is the usage of goto in go language?. For more information, please follow other related articles on the PHP Chinese website!