当前位置:网站首页>Self study the definition of golang [3.5go language array, range keyword] array, and use the for loop to traverse one-dimensional array
Self study the definition of golang [3.5go language array, range keyword] array, and use the for loop to traverse one-dimensional array
2022-07-22 08:35:00 【Aspire to be a doctor】
Catalog
1. Define an integer array , The quantity is written before the type
2. Let the compiler count without defining the size
3. Define a 4 That's ok 5 Column array and output
4. use for Loop through a one-dimensional array
6. use range Keyword output subscript and its corresponding value
Code summary of this chapter :
1. Define an integer array , The quantity is written before the type
var arr1 [5]int // Define an integer array , The quantity is written before the type
2. Let the compiler count without defining the size
arr3 := [...]int{2, 4, 6, 8, 10} // Let the compiler count without defining the size
3. Define a 4 That's ok 5 Column array and output
var grid [4][5]int // Define a 4 That's ok 5 Column array and output
fmt.Println(grid)
4. use for Loop through a one-dimensional array
// Traversal array
for i := 0; i < len(arr3); i++ { // use for Loop through a one-dimensional array
fmt.Println(arr3[i])
}
5. Use range Traversal array
for i := range arr3 { // use range Keyword traverse one-dimensional array , Same as the previous line
fmt.Println(arr3[i])
}
6. use range Keyword output subscript and its corresponding value
for i, v := range arr3 { // use range Keyword output subscript and its corresponding value
fmt.Println(i, v)
}
summary
Code summary of this chapter :
package main
import "fmt"
func main() {
var arr1 [5]int // Define an integer array , The quantity is written before the type
arr2 := [3]int{1, 3, 5}
arr3 := [...]int{2, 4, 6, 8, 10} // Let the compiler count without defining the size
fmt.Println(arr1, arr2, arr3)
var grid [4][5]int // Define a 4 That's ok 5 Column array and output
fmt.Println(grid)
// Traversal array
for i := 0; i < len(arr3); i++ { // use for Loop through a one-dimensional array
fmt.Println(arr3[i])
}
for i := range arr3 { // use range Keyword traverse one-dimensional array , Same as the previous line
fmt.Println(arr3[i])
}
for i, v := range arr3 { // use range Keyword output subscript and its corresponding value
fmt.Println(i, v)
}
}
Output :
[0 0 0 0 0] [1 3 5] [2 4 6 8 10]
[[0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0]]
2
4
6
8
10
2
4
6
8
10
0 2
1 4
2 6
3 8
4 10
Run a screenshot :
边栏推荐
- Location Cache 模块浅析及 OCP 监控、报警详解
- Soft test intermediate [Database System Engineer] Chapter 0: how to prepare for the test by self-study, test introduction, test preparation materials, size score distribution in the morning and aftern
- Integrate efk with odoo to realize log visualization
- Pytoch learning (I) Deep learning review and introduction to pytoch
- Redis的经典三问以及哨兵
- 使用 SUM 函数对区域中的数字求和
- Verilog应用——24秒篮球计数器
- 交易进阶必由之路:从小白到稳定盈利(三)
- activiti默认模型ER图
- 数据分析与挖掘1
猜你喜欢
张驰咨询:某包装印刷集团第五期六西格玛项目通过专家评审
Seven / four / five layer network model
MySQL transaction
grpc-middleware实现grpc调用重试
excel 中粘贴时怎么不覆盖
“珠峰”架构强势赋能 第三代荣威RX5/超混eRX5刷新产品力“天花板”
September memo
软考中级【数据库系统工程师】第2章:程序语言基础知识,自学软考笔记,程序语言概述程序语言翻译基础低级语言和高级语言编译和解释的区别中缀、前缀与后缀表达式程序语言的数据成分1)常量和变量2)全局变量和局
量化交易日记-2021年02月总结
Location Cache 模块浅析及 OCP 监控、报警详解
随机推荐
CDH 6.1 environment construction graphic tutorial
The difference and implementation of MyISAM and InnoDB in MySQL
MySQL stored procedure
Airflow scheduling start_ Date explanation
量化交易中的三类行情
MySQL存储过程
自学golang【第一章:go语言基础知识】为什么要学习go语言?go语言与c语言的关系?go语言创始人?go语言的特性有哪些?go语言适合做什么?国内外有哪些企业或项目使用go语言?
FastJson、JackJson处理时间、日期问题注意事项
MySQL中MyISAM和InnoDB的区别与实现
Verilog——篮球24S计时器
软考中级【数据库系统工程师】第1章:计算机系统知识,自学软考笔记,备考2022年5月份软考,计算机硬件系统CPU组成指令寄存器组总线输入输出的程序控制方式计算机体系结构与存储系统加密技术流水线技术
excel 中粘贴时怎么不覆盖
同个一个工作簿下多个工作表相同格式
pytorch如何将Variable或Tensor转换为numpy?
自学golang【3.7map的练习代码】
STM32 SPI 读取数据不准确,只有第一次对,后边均不对
IDEA 如何自动导入(import)
TPS trading strategy with a winning rate of 93.98%
Location Cache 模块浅析及 OCP 监控、报警详解
Verilog——74HC194多功能双向移位寄存器