Home>Article>Backend Development> What is the usage of goto in go language?

What is the usage of goto in go language?

王林
王林 Original
2021-02-04 18:01:37 12448browse

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.

What is the usage of goto in go language?

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

What is the usage of goto in go language?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn