当前位置:网站首页>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)
}
边栏推荐
- Pytoch viewing model parameter quantity and calculation quantity
- [recruitment (Guangzhou)] Chenggong Yi (Guangzhou) Net core middle and Senior Development Engineer
- 知识传播不能取代专业学习!
- DeFi“钱从哪来”?一个大多数人都没搞清楚的问题
- Simple understanding of the difference between get request and post submission
- How to execute a query SQL
- "Persistent diseases" that cannot be solved in IM application development
- Step by step | help you easily submit Google play data security form
- 【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
- Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
猜你喜欢

Observable, seulement fiable: première bombe de salon de la série cloudops d'exploitation et d'entretien automatisés dans le nuage

Google Earth Engine(GEE)——将字符串的转化为数字并且应用于时间搜索( ee.Date.fromYMD)

单元测试效率优化:为什么要对程序进行测试?测试有什么好处?

一文讲清楚什么是类型化数组、ArrayBuffer、TypedArray、DataView等概念

mysql拒绝访问、管理员身份打开的
![【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)](/img/5a/eaa845f4332f0b8ee8b6409d6a79e8.png)
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)

Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
![[KALI] KALI系统、软件更新(附带镜像源)](/img/ac/43a3f81d50ab6866271b500b142252.png)
[KALI] KALI系统、软件更新(附带镜像源)

编程实战赛来啦!B站周边、高级会员等好礼送你啦!

navicat数据库建表是没有utf8选项。
随机推荐
嵌入式开发:5个可能不再被禁止的C特征
get请求与post提交区别的简易理解
Tencent two sides: @bean and @component are used on the same class. What happens?
Pytorch查看模型参数量和计算量
Google Earth Engine(GEE)——将字符串的转化为数字并且应用于时间搜索( ee.Date.fromYMD)
Apache Doris Compaction優化百科全書
这个编辑器即将开源!
“即服务”,企业数字化转型的必然选择
【刷题篇】避免洪水泛滥
Meaning of while (~scanf ("%d%d", & A, & B))
Je suis à Foshan, où puis - je ouvrir un compte? L'ouverture d'un compte par téléphone mobile est - elle sécurisée?
Wuenda 2022 machine learning special course evaluation is coming!
步骤详解 | 助您轻松提交 Google Play 数据安全表单
知识传播不能取代专业学习!
【科研数据处理】[基础]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
Configuration of headquarters dual computer hot standby and branch infrastructure for firewall Foundation
Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
How does MySQL merge columns?
【科研数据处理】[实践]类别变量频数分析图表、数值变量分布图表与正态性检验(包含对数正态)
深入理解.Net中的线程同步之构造模式(二)内核模式3.内核模式构造物Mutex