我试图理解为什么这种情况总是会发生

I'm trying to understand why in this select statement the first case always goes off and does not wait for the channel to be filled. For this program I'm trying to get the program to wait till all the channels have been filled and whenever a channel is filled by the method it is put in the first available space in the array of channels

I tried putting the line <-res[i] in the case statement but for some reason this case always goes off regardless of whether or not the channels have a value.

package main

import (
    "fmt"
    "math"
    "math/rand"
    "time"

)

func numbers(sz int) (res chan float64) {
    res = make(chan float64)
    go func() {
        defer close(res) 
        num := 0.0
        time.Sleep(time.Duration(rand.Intn(1000)) *time.Microsecond)
        for i := 0; i < sz; i++ {
            num += math.Sqrt(math.Abs(rand.Float64()))
        }
        num /= float64(sz)
        res <- num
        return
    }()
    return
}

func main() {
    var nGo int
    rand.Seed(42)
    fmt.Print("Number of Go routines: ")
    fmt.Scanf("%d 
", &nGo)
    res := make([]chan float64, nGo)
    j:=0
    for i := 0; i < nGo; i++ {  
        res[i] =numbers(1000)
    }
    for true{
        for i := 0; i < nGo;  {
            select {
                case <-res[i]:{
                    res[j]=res[i]//this line
                    j++
                }
                default:
                i++



            }
        }
        if j==nGo{
            break 
        }
    }

        fmt.Println(<-res[nGo-1])


}

The print line should print some float.

<-res[i] in the case statement but for some reason this case always goes off regarless of wether or not the channels has a value

It will only not choose this case if the channel's buffer is full (i.e. a value cannot be sent without blocking). Your channel has a buffer length equal to the number of values you're sending on it, so it will never block, giving it no reason to ever take the default case.