为什么用_空白标识符进行范围迭代会产生不同的值

I'm learning Go and having a great time so far.

The following code outputs the sum as 45

package main
import "fmt"

func main(){
   //declare a slice
   numSlice := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
   var sum int = 0

   for num := range numSlice {                                                                                           
      sum += num
      fmt.Println("num =", num)
   }
   fmt.Println("sum =", sum)   
}

The following code, where I use _ the blank identifier to ignore the index in the for declaration outputs the sum as 55

//declare a slice
numSlice := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
var sum int = 0

for _,num := range numSlice {                                                                                           
   sum += num
   fmt.Println("num =", num)
}
fmt.Println("sum =", sum)   

This has got me slightly stumped. From my understanding the blank identifier is used to ignore the slice index . But it also seems to be shifting the index and thereby ignoring the last element in the slice.

Can you please explain what's happening here and possibly why. I'm assuming this is not a bug and is by design. Go is so well designed so what would the possible use cases be for this kind of behaviour?

Single parameter range uses indexes, not values. Because your indexes are also going up from 0 to 9 using range with a single param will add the indexes up from 0 to 9 and give you 45

package main
import "fmt"

func main(){
   //declare a slice
   numSlice := []int{0, 0, 0, 0}
   var sum int = 0

   for num := range numSlice {                                                                                           
      sum += num
      fmt.Println("num =", num)
   }
   fmt.Println("sum =", sum)   
}

Output

num = 0
num = 1
num = 2
num = 3
sum = 6