Created
May 6, 2019 21:14
-
-
Save brydavis/ab326b224e129c94d946e686fdeeb285 to your computer and use it in GitHub Desktop.
Looping over a slice of strings continuously
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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