Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select with single case blocks, adding default: unblocks

Tags:

While testing some code with something like this:

// ch := make(chan error)

for {
    select {
      case <- ch:
           println("here")
    }
}

I notice that if I don't add a default the code blocks:

for {
    select {
       case <- ch:
            println("here")
       default:
    }
}

In case that the block is required, could't be better then just use range, something like:

for {
    for _ = range <- ch {
        println("here")
    }
}

Or is there any difference/advantage of using select over range for this case ?