当前位置:网站首页>For loop of go language foundation
For loop of go language foundation
2022-06-23 07:52:00 【Ink purple feather ink】
One 、 Loop statement
Loop statements are used to repeatedly execute a piece of code .
for yes Go The only loop statement in language .
Go Linguistic For Circulatory 3 In the form of , Only one of them uses semicolons .
for init; condition; post { }
for condition { }
for { }init: It's usually an assignment expression , Assign initial values to control variables ; condition: A relational or logical expression , Cycle control conditions ; post: It's usually an assignment expression , Increment or decrement of a control variable . for The execution of the statement is as follows :
- Let's start with the expression
initAssign initial value to ; - Discriminating assignment expression init Whether the given
conditionConditions , If the value is true , Satisfy the cyclic condition , Then execute the statement inside the loop , And then executepost, Enter the second loop , Judge againcondition; Otherwise, judgmentconditionThe value of is false , Not meeting the conditions , On termination for loop , Execute the out of loop statement .
and if Conditional statements are the same , Loop statements can also be nested
for [condition | ( init; condition; increment ) | Range]
{
for [condition | ( init; condition; increment ) | Range]
{
statement(s)
}
statement(s)
}Two 、 Cycle control
breakStatement is used to terminate abruptly before completing normal execution for loop , Then the program will be in for The next line of the loop starts executing .continueStatements are used to jump out offorThe current loop in the loop . staycontinueAll after the statementforLoop statements are not executed in this loop . The loop will continue to execute in the next loop .
3、 ... and 、 Example
package main
import "fmt"
func test1() {
// normal for loop
for i := 0; i < 3; i++ {
fmt.Printf("i=%d\t", i)
}
}
func test2() {
// Anamorphic writing
i := 0
for i < 3 {
fmt.Printf("i=%d\t", i)
i = i + 1
}
}
func main() {
test1()
fmt.Println()
test2()
}Four 、 Infinite loop
func test3() {
for true {
fmt.Println("Hello World")
}
}
// Or just put true Also omitted
func test3() {
for {
fmt.Println("Hello World")
}
} tip : Infinite loop careful use ,Ctrl+c You can stop the examples in this article .
边栏推荐
- 职场必备的30套报表模板,满足95%的报表需求,一键套用无需代码
- imperva-查找正则匹配超时的方法
- MIT CMS.300 Session 12 – IDENTITY CONSTRUCTION 虚拟世界中身份认同的建立 part 2
- 某年某月某公司的面试题(1)
- The eighth experiment of hcip Road
- php序列化和反序列化-ctf
- 1278_ FreeRTOS_ Understand the delayed task with the prvaddcurrenttasktodelayedlist interface
- 1.概率论-组合分析
- three. Solution to stripe shadow and grid shadow in JS
- Talk about routing design in service governance
猜你喜欢

YGG Spain subdao Ola GG officially established

QT project error: -1: error: cannot run compiler 'clang++' Output:mingw32-make. exe
three. Solution to stripe shadow and grid shadow in JS

1278_FreeRTOS_借助prvAddCurrentTaskToDelayedList接口理解delayed task

imperva-查找正则匹配超时的方法

PHP 文件包含 -ctf

C WPF realizes dynamic loading of controls through binding

深度学习------不同方法实现vgg16

Using the for loop to output an alphabetic triangle

通过端口查文件
随机推荐
[Laoke] how should ordinary people learn technology?
GIF验证码分析
Display proportion of sail soft accumulation diagram
Unity to wechat applet games
Query on the performance of multi table view in MySQL
Tri rapide + Tri par bulle + Tri par insertion + Tri par sélection
Detailed explanation of redis persistence, master-slave and sentry architecture
数学知识:欧拉函数—欧拉函数
JS to determine the added and decreased elements of two arrays
YGG 西班牙 subDAO——Ola GG 正式成立
google常用语法
这道字符串反转的题目,你能想到更好的方法吗?
Acwing第 56 场周赛【完结】
【Try to Hack】ip地址
浅谈ThreadLocal和InheritableThreadLocal,源码解析
Guava cache usage summary
Playwirght getting started
【markdown】markdown 教程大归纳
3DMAX plug-in development environment configuration and fileexport and utilities template testing
通过端口查文件