Home>Article>Backend Development> There are several types of golang loops
Go languageprovides the following types of loop processing statements:
Loop types |
Description |
---|---|
for loop | Repeated execution of statement blocks |
Loop nesting | Nest one or more for loops within a for loop |
for loop:
The for loop is a loop control Structure that can execute a specified number of loops.
Syntax
There are 3 forms of For loop in Go language, only one of which uses semicolon.
Same as for in C language:
for init; condition; post { }
Same as while in C:
for condition { }
Same as for(;;) in C:
for { }
Loop Nesting
The Go language allows users to use loops within loops. Next we will introduce the use of nested loops.
Grammar
The following is the format of nested loops in Go language:
for [condition | ( init; condition; increment ) | Range] { for [condition | ( init; condition; increment ) | Range] { statement(s); } statement(s); }
For more golang knowledge, please pay attention to thegolang tutorialcolumn on the PHP Chinese website.
The above is the detailed content of There are several types of golang loops. For more information, please follow other related articles on the PHP Chinese website!