有没有办法在Golang中迭代一系列整数? [英] Is there a way to iterate over a range of integers in Golang?
本文介绍了有没有办法在Golang中迭代一系列整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for i:= range [1..10] {
fmt.Println(i)
}
或者有没有一种方法可以像Goy那样表示Go中的整数范围?
解决方案
你可以,也应该写一个for循环。简单明显的代码就是Go方式。
for i:= 1;我<= 10; i ++ {
fmt.Println(i)
}
Golang's range can iterate over maps and slices, but I was wondering if there is a way to iterate over a range of numbers, something like this
for i := range [1..10] {
fmt.Println(i)
}
or is there a way to represent range of integers in Go like how ruby does?
解决方案
You can, and should, just write a for loop. Simple, obvious code is the Go way.
for i := 1; i <= 10; i++ {
fmt.Println(i)
}
这篇关于有没有办法在Golang中迭代一系列整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文