Go关键字--continue


友情推广
在这里插入图片描述

continue

continue主要用于for循环语句中,用于改变程序执行顺序。当在循环语句中使用continue后,将会跳转到循环开始处继续运行。如下边的示例:

package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println("begin")
	for {
		fmt.Println("hello world")
		time.Sleep(time.Second * 1)
		continue
		fmt.Println("hi")
	}
}

输出信息是:

begin
hello world
hello world
......

从输出信息可以看出循环语句中出现continue后,将会跳转到循环开始的地方开始运行,continue后边的代码将不会被执行。

猜你喜欢

转载自blog.csdn.net/hzwy23/article/details/82874552
今日推荐