For:
for is the only looping construct in Go. Here are few example of for loops:
func main() { //for loop with single condition i := 1 for i <= 10 { fmt.Println(i) i++ } //for loop with initialization/condition/after for i := 1; i <= 10; i++ { fmt.Println(i) } // for loop with break/return -- for without condition will loop // repeatedly until you break or return k := 5 for { if k == 2 { return } fmt.Println(k) k-- } }
Happy Coding 🤖
Comments
Post a Comment