Go - Loops

There are many regular repetitive operations in many practical problems, so some statements need to be repeated in the program.

The Go language provides the following types of loop processing statements:

Sr.No Loop Type & Description
1 for loop

Repeat statement block

2 nested loops

Nest one or more for loops in a for loop

loop control statement

The loop control statement can control the execution of statements in the loop body.

The GO language supports the following loop control statements:

Sr.No Control Statement & Description
1 break statement

Often used to interrupt the current for loop or jump out of a switch statement

2 continue statement

continue the remaining statements of the current loop and proceed to the next iteration..

3 goto statement

Transfer control to the goto statement.

The Infinite Loop

If the conditional statement in the loop is never false, an infinite loop will occur, and we can execute an infinite loop by setting only one conditional expression in the for loop:

package main

import "fmt"

func main() {
   for true  {
       fmt.Printf("This loop will run forever.\n");
You may have an initialization and increment expression.