I was assuming I can use any operator to increment the incrementing variable in for loop. Looks like it's not the case. Following code loops for ever.
import (
"fmt"
)
func main() {
for i:=0; i<10; i=i*2{
fmt.Println(i)
}
}
Following code works fine.
import (
"fmt"
)
func main() {
for i:=0; i<10; i=i+2{
fmt.Println(i)
}
}
Your loop starts at i := 0
, so you are just continuously doing i := 0 * 2
, so you get an infinite loop (as you should), since 0 < 10
and i
never actually gets bigger.