Infinite loop behavior in Go lang [closed]
The following code outputs zeroes in the console var i uint = 0 func show() { for { fmt.Println(i) time.Sleep(500 * time.Millisecond) } } func main() { go show() for { i++ } } output: 0 0 0 0 ... Only if I change the condition in 'for' to something like "for range 1
The following code outputs zeroes in the console
var i uint = 0
func show() {
for {
fmt.Println(i)
time.Sleep(500 * time.Millisecond)
}
}
func main() {
go show()
for {
i++
}
}
output: 0 0 0 0 ...
Only if I change the condition in 'for' to something like "for range 1<<32 - 1" it will output increasing values, e.g.: 4940 277284440 558609614 838787066 ....
Could someone please tell why it doesn't work the same way using an infinite loop?