I seem to be having a queer problem while getting user input within a for loop in go. Here is my code
package main
import "fmt"
func main() {
var num int
for i := 0; i < 10; i++ {
fmt.Printf("Debug: i : %d ", i)
fmt.Scanf("%d", &num)
fmt.Println(num)
}
}
What happens when I run this code is this :
Debug: i : 0
Enter next number
1
1
Debug: i : 1
Enter next number
1
Debug: i : 2
Enter next number
2
2
Debug: i : 3
Enter next number
2
Debug: i : 4
Enter next number
3
3
Debug: i : 5
Enter next number
3
Debug: i : 6
Enter next number
4
4
Debug: i : 7
Enter next number
4
Debug: i : 8
Enter next number
5
5
Debug: i : 9
Enter next number
5
What I notice is that each iteration of the loop happens twice, Could this be because Go is using parallelism by default and causing both processors to run the code within a for loop?