May 11, 2021 Go
There are many regular repetitions in many practical problems, so some statements need to be repeated in the program.
Here's a flowchart of most programming language loopers:
The Go language provides several types of circular processing statements:
The type of loop | Describe |
---|---|
For loop | Repeat the statement block |
Loop nesting | Nest one or more for loops in a for loop |
Loop control statements control the execution of statements in the loop body.
The GO language supports the following loop control statements:
The control statement | Describe |
---|---|
Break statement | Often used to interrupt the current for loop or jump out of a switch statement |
The continue statement | Skip the remaining statements of the current loop, and then proceed to the next loop. |
Goto statement | Transfer control to the marked statement. |
If a conditional statement in a loop is never false, an infinite loop is performed, and we can execute an infinite loop by setting only one conditional expression in the for loop statement:
package main import "fmt" func main() { for true { fmt.Printf("这是无限循环。\n"); } }