个性化阅读
专注于IT技术分析

Go goto语句

点击下载

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
赞(0)
未经允许不得转载:srcmini » Go goto语句

评论 抢沙发

评论前必须登录!