github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume1/section2/loopdemo/loopdemo.go (about) 1 // Various examples of Go's for loop. 2 package main 3 4 import ( 5 "fmt" 6 "time" 7 ) 8 9 func main() { 10 11 // Classic for loop 12 for i := 0; i < 10; i++ { 13 14 if i == 0 { 15 continue 16 } 17 18 fmt.Println("Inside classic for loop, value of i is:", i) 19 20 } 21 fmt.Println("\n\n") 22 23 // Single condition for loop 24 j := -20 25 for j != 0 { 26 fmt.Println("Inside single condition loop, value of j is:", j) 27 j++ 28 } 29 fmt.Println("\n\n") 30 31 loopTimer := time.NewTimer(time.Second * 9) 32 // An infinite loop, don't worry we'll break out of it in 9 seconds 33 for { 34 35 fmt.Println("Inside the infinite loop!") 36 37 <-loopTimer.C 38 break 39 40 } 41 42 }