Go language has goto statement. The goto statement of Go language can unconditionally transfer to the specified line in the process; the goto statement is usually used in conjunction with conditional statements and can be used to implement conditional transfers, jump out of loops and other functions.
Demo environment for this article: Windows 7 system, Go1.11.2 version, Dell G3 computer.
Go language has goto statement.
Recommended tutorial: "golang"
The use of goto in go language
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, the use of goto statements is generally not recommended to avoid confusing the program flow and making it difficult to understand and debug the program
Grammar
The syntax format of goto is as follows:
goto label; .. . label: statement;
2. Goto flow chart
3. Case
package main import "fmt" func main() { var a = 10 LOOP: fmt.Println("执行了goto") for a < 20 { if a == 15 { a += 1 //a满足条件 15+1 goto LOOP // 因为上面条件满足了 到这条goto语句就会跳转到LOOP:执行 } fmt.Printf("a的值为:%d\n", a) a++ } }
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of Does go language have goto?. For more information, please follow other related articles on the PHP Chinese website!