📜  GO语言 range

📅  最后修改于: 2021-01-02 09:06:52             🧑  作者: Mango

转到声明

Go goto语句是一个跳转语句,用于将控件转移到程序的其他部分。

在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