What is the usage of goto in go language?

王林
Release: 2023-01-13 00:21:44
Original
12540 people have browsed it

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("走这里")
}
 
//结果输出:走这里
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template