使用嵌套循环遍历二维数组或切片,如下所示: arr := [][]int{ {1, 2, 3}, {4, 5,
arr := [][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr[i]); j++ {
fmt.Println(arr[i][j])
}
}
arr := [][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
for _, row := range arr {
for _, val := range row {
fmt.Println(val)
}
}
arr := [][]int{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
}
for i, row := range arr {
for j, val := range row {
fmt.Printf("arr[%d][%d] = %d\n", i, j, val)
}
}
--结束END--
本文标题: Go中遍历二维数组或切片的技巧有哪些
本文链接: https://lsjlt.com/news/594478.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0