switch
switch does not fall through by default. Cases can be expressions and fallthrough is explicit.
Example
package main
import "fmt"
func main() {
n := 3
switch {
case n < 0:
fmt.Println("neg")
case n < 5:
fmt.Println("small")
fallthrough
default:
fmt.Println("fell")
}
}Result
small fell
Exercise
Force fall through.
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.