YouTip LogoYouTip

Go Continue Statement

# Go Language continue Statement [![Image 4: Go Language Loop Statements](#)Go Language Loop Statements](#) The continue statement in Go is somewhat similar to the break statement. However, continue does not exit the loop; instead, it skips the current iteration and proceeds to the next iteration of the loop. In a for loop, executing the continue statement triggers the execution of the for increment statement. In nested loops, you can use a label to specify which loop you want to continue. ### Syntax The syntax for continue is as follows: continue; The flowchart for the continue statement is shown below: !(#) ### Example Skip the current loop iteration and proceed to the next when variable a equals 15: ## Example package main import"fmt" func main(){ /* Define local variables */ var a int=10 /* for loop */ for a <20{ if a ==15{ /* Skip this iteration */ a = a +1; continue; } fmt.Printf("The value of a is: %dn", a); a++; } } The execution result of the above example is: The value of a is: 10 The value of a is: 11 The value of a is: 12 The value of a is: 13 The value of a is: 14 The value of a is: 16 The value of a is: 17 The value of a is: 18 The value of a is: 19 The following example demonstrates the difference between using a label and not using one in nested loops: ## Example package main import"fmt" func main(){ // Without label fmt.Println("---- continue ---- ") for i:=1;i<=3;i++{ fmt.Printf("i: %dn",i) for i2 :=11; i2 <=13; i2++{ fmt.Printf("i2: %dn", i2) continue } } // With label fmt.Println("---- continue label ----") re: for i:=1;i<=3;i++{ fmt.Printf("i: %dn",i) for i2 :=11; i2 <=13; i2++{ fmt.Printf("i2: %dn", i2) continue re } } } The execution result of the above example is: ---- continue ---- i: 1 i2: 11 i2: 12 i2: 13 i: 2 i2: 11 i2: 12 i2: 13 i: 3 i2: 11 i2: 12 i2: 13---- continue label ---- i: 1 i2: 11 i: 2 i2: 11 i: 3 i2: 11 [![Image 6: Go Language Loop Statements](#)Go Language Loop Statements](#)
← Android Intents FiltersAndroid List Fragment β†’