Skip to content

Instantly share code, notes, and snippets.

@brydavis
Created May 6, 2019 21:14
Show Gist options
  • Save brydavis/ab326b224e129c94d946e686fdeeb285 to your computer and use it in GitHub Desktop.
Save brydavis/ab326b224e129c94d946e686fdeeb285 to your computer and use it in GitHub Desktop.
Looping over a slice of strings continuously
package main
import (
"fmt"
"time"
)
func main() {
list := []string{"abc", "def", "ghi", "jkl", "mno", "p"}
i := 0
for {
fmt.Println(list[i])
if i+1 == len(list) {
i = 0
} else {
i++
}
time.Sleep(2 * time.Second)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment