当前位置:网站首页>Go language for loop multivariable use
Go language for loop multivariable use
2022-06-30 14:07:00 【Zhen Jie.】
go for The loop syntax is :
/* 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 init; condition; post {
//......
}
When using multiple variables , Use parallel assignment , One thing to keep in mind is that post It's about Writing , The code is as follows :
/* Wrong writing : 1. Do not conform to the for init; condition; post { } Format , Multivariable assignment can only use parallel assignment ; 2.++ -- Statements, not expressions, cannot be used i++、j++ , You should use i = i + 1、 j = j + 1 */
func main() {
sum := 0
for i, j := 1, 10; i < j; i++,j++ {
sum += i + j
}
fmt.Println("sum is equal to ", sum)
}
/* Write it correctly */
func main() {
sum := 0
for i, j := 1, 10; i < j; i, j = i+1, j+1 {
//1. accord with for Cyclic init;condition;post Format .2. Use expressions correctly :i = i + 1, j = j + 1
sum += i + j
}
fmt.Println("sum is equal to ", sum)
}
边栏推荐
- SQL programming problem, test case failed
- 智慧运维:基于 BIM 技术的可视化管理系统
- Meaning of while (~scanf ("%d%d", & A, & B))
- 损失函数:DIOU loss手写实现
- Click the TD cell of table to open the dialog pop-up window. After obtaining the value, put the value back into the TD cell
- Google Earth Engine(GEE)——将字符串的转化为数字并且应用于时间搜索( ee.Date.fromYMD)
- Introduction to the renewal of substrate source code: the pallet alliance is incorporated into the main line,
- Dart 扩展特性
- Introduction to reverse commissioning - VA and RVA conversion in PE 04/07
- VisualStudio and SQL
猜你喜欢
【观察】智能产业加速,为何AI算力要先行?
[Title brushing] heater
Apache Doris Compaction優化百科全書
Today's sleep quality record 80 points
SQL编程问题,测试用例不通过
IM即时通讯应用开发中无法解决的“顽疾”
“即服务”,企业数字化转型的必然选择
Introduction to reverse commissioning - VA and RVA conversion in PE 04/07
Wuenda 2022 machine learning special course evaluation is coming!
Read all the knowledge points about enterprise im in one article
随机推荐
【刷题篇】避免洪水泛滥
Observable, seulement fiable: première bombe de salon de la série cloudops d'exploitation et d'entretien automatisés dans le nuage
MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
随着产业互联网的发展,有关互联网的落地和应用也就变得宽阔了起来
Why can't the database table be written into data
Mysql database foundation: stored procedures and functions
DNS resolution home network access public DNS practice
[Title brushing] avoid flooding
Pytorch查看模型参数量和计算量
Jetpack Compose 实现完美屏幕适配
半导体动态杂谈
重磅:国产IDE发布,由阿里研发,完全开源!
Prometheus 2.29.0 新特性
[scientific research data processing] [basic] category variable frequency analysis chart, numerical variable distribution chart and normality test (including lognormal)
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
Meaning of while (~scanf ("%d%d", & A, & B))
步骤详解 | 助您轻松提交 Google Play 数据安全表单
Service online governance
Unity animator parameter
How to take the first step in digital transformation