Go continue语句

继续用于跳过循环的其余部分, 然后在检查条件之后继续循环的下一个迭代。
句法:-

continue;

或者我们可以喜欢
x: continue:x

【Go continue语句】继续执行语句示例:
package mainimport "fmt"func main() {/* local variable definition */var a int = 1/* do loop execution */for a < 10 {if a == 5 {/* skip the iteration */a = a + 1; continue; }fmt.Printf("value of a: %d\n", a); a++; }}

输出:
value of a: 1value of a: 2value of a: 3value of a: 4value of a: 6value of a: 7value of a: 8value of a: 9

继续也可以应用于内循环
转到带有内部循环示例的Continue语句:
package mainimport "fmt"func main() {/* local variable definition */var a int = 1var b int = 1/* do loop execution */for a = 1; a < 3; a++ {for b = 1; b < 3; b++ {if a == 2 & & b == 2 {/* skip the iteration */continue; }fmt.Printf("value of a and b is %d %d\n", a, b); }fmt.Printf("value of a and b is %d %d\n", a, b); }}

输出:
value of a and b is 1 1value of a and b is 1 2value of a and b is 1 3value of a and b is 2 1value of a and b is 2 3

    推荐阅读