go的fallthrough玩一下

     遇到了,看一下:

package main

import "fmt"

func main() {
    b := false

    switch b {
    case false:
            fmt.Println("1")
            fallthrough
    case true:
            fmt.Println("2")
            fallthrough
    case false:
            fmt.Println("3")
            fallthrough
    case true:
            fmt.Println("4")
    case false:
            fmt.Println("5")
            fallthrough
    default:
            fmt.Println("default case")
    }
}

         结果:

1
2
3
4

 

        假如b为true, 结果为:

2
3
4

       没什么好说的。

 


版权声明:本文为stpeace原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。