A new product!

Social Media Toolkit

Download our all in one automation tool for various social media websites.

Gopher

Continue Statement in Golang

Published on 29 March 2020
Last Updated on 29 March 2020

Continue statement forces the code between current iteration and next iteration to be skipped and program flow resumes on the next iteration.

Continue statement is used for immediately forcing the next iteration in the loop.

Program to demonstrate use of Continue statement in Golang

Program given below demonstrates how to use continue statement inside a for loop.

package main

import (
	"fmt"
)

func main() {
	for a := 0; a < 4; a++ {
		if a == 2 {
			continue
		}
		fmt.Println("a is:", a)
	}
}

Program output

Above program produces following output:

a is: 0
a is: 1
a is: 3

Program Description

Above program makes use of a continue statement inside a for loop. If the condition above the continue statement is met, then continue statement will be executed.

Once continue statement is executed, it forces the code between current iteration and next iteration to be skipped and program flow resumes to the next iteration.