Home  >  Article  >  Backend Development  >  There are several types of golang loops

There are several types of golang loops

尚
Original
2020-01-13 11:08:232709browse

There are several types of golang loops

Go language provides 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 the golang tutorial column 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn