GO教程
GO控制语句
GO高级

Go Goto

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 

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4