package main import "fmt" // // Demonstrate a problem whereby a uint8 loop variable in a nested loop results in // the loop variable an enclosing loop not being incremented. // // go version go1.2 linux/amd64 // ubuntu 12.04 // // The program should terminate but it gets stuck in the second loop. // func main() { loop1() loop2() } const lim = int(1 << 7) const inc = 64 // loop1 works: ii increments as expected. // func loop1() { for ii := 0; ii < lim; ii += inc { for jj := 0; jj < lim; jj += inc { fmt.Printf("%d %d\n", ii, jj) } } } // loop2 doesn't work: // on my desktop ii doesn't increment, // on play.golang.org it results in the server error: "Error communicating with remote server." // // It's the uint8 that triggers the problem. // func loop2() { for ii := 0; ii < lim; ii += inc { for jj := int8(0); int(jj) < lim; jj += inc { fmt.Printf("%d %d\n", ii, jj) } } }