Created
April 20, 2023 15:38
-
-
Save kitlabcode/92a96ca18f0071b18702df9aacbda565 to your computer and use it in GitHub Desktop.
When loop meets a condition start the loop over again.
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" | |
| func main() { | |
| slice := []int{1, 2, 3, 4, 5} | |
| var count int | |
| for i := 0; i < len(slice); i++ { | |
| fmt.Println(slice[i]) | |
| count++ | |
| if count == 2 { | |
| i = -1 // restart from the beginning | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment