goloop tries to facilitate looping in Go.
go get -u github.com/dushaoshuai/goloop
Replace this trivial code:
for i := 0; i < 10; i++ {
fmt.Println(i)
}
with:
for i := range goloop.Repeat(10) {
fmt.Println(i)
}
Break the loop when certain conditions are met:
for i := range goloop.RepeatWithBreak(10) {
fmt.Println(i.I)
if i.I == 5 {
i.Break()
}
}
Range over a sequence of integers:
for i := range goloop.Range(3, 26, 5) {
fmt.Println(i.I)
if i.I >= 18 {
i.Break()
}
}
Range over a sequence of integers from a slice:
for i, n := range goloop.RangeSlice[uint8](250, 255) {
fmt.Println(i, n)
if n >= 253 {
break
}
}