The length of nil slice, map, and channel are 0.
What's the expected behaviour of loop when the range expression
evaluates to nil?
- Martin
A "for" statement with a "range" clause iterates through all entries of an array, slice, string or map, or values received on a channel. For each entry it assigns iteration values to corresponding iteration variables and then executes the block.
They'll all execute zero times, except for the channel case, which
will panic ("range over a nil channel"). Outside of s special case in
select, with specific purpose, nil channels are never helpful,
although you can ask their length. This should be clarified in the
spec, one way or the other.
-rob