Latest web development tutorials

Go Language loop

There are many repeat regularity in many practical problems, so the program will need to repeat certain statements.

The following is a flow chart programming language mostly cycle programs:

Go language provides the following types of loop processing statements:

Type of cycle description
for loop The statements are repeated
Nested loop One or more nested for loop in for loop

Loop control statements

Loop control statements control the execution of the loop body statement.

GO loop control language supports the following statements:

Control statements description
break statement Often used to interrupt the current for loop or out of the switch statement
continue Statement Skip the remaining statements of the current cycle, and then continue with the next cycle.
goto statement Transfers control to the labeled statement.

Infinite loop

Such as over a loop conditional statement is false is never infinite loop, we can set a conditional expression only through the for loop statement to execute an infinite loop:

package main

import "fmt"

func main() {
    for true  {
        fmt.Printf("这是无限循环。\n");
    }
}