[Solved] Nested loops array in Go not behaving like other languages’ array


Because you are filling x[i] with each of the values of scores.
You have one extra loop.

Since the last value of the slice scores is 83, you are filling x one more time, with 83 for each slot.

Simpler would be:

for i, _ := range x {
    // fill up x array with elements of scores array
    x[i] = scores[i]
}

play.golang.org

Output: [98 93 77 82 83]

2

solved Nested loops array in Go not behaving like other languages’ array