Go Goto基础教程文档

收录于 2023-04-20 00:10:05 · بالعربية · English · Español · हिंदीName · 日本語 · Русский язык · 中文繁體

Go Goto 语句

Go goto 语句是一个跳转语句,用于将控制权转移到程序的其他部分。
在goto语句中,必须有一个标签。我们使用标签来转移程序的控制权。
Go Goto 语句示例:
package main
import (
   "fmt"
)
func main() {
   var input int
Loop:
   fmt.Print("You are not eligible to vote ")
   fmt.Print("Enter your age ")
   fmt.Scanln(&input)
   if (input <= 17) {
      goto Loop
   } else {
      fmt.Print("You can vote ")
   }
}
输出:
You are not eligible to vote 
Enter your age 15
You are not eligible to vote 
Enter your age 18
You can vote