LoginSignup
1
0

More than 3 years have passed since last update.

golang switch fallthrough

Posted at

golang の switchで使う fallthroughを試してみた

次のcase文に、条件に関わらずに進む。
この例だと、Aの条件が成立して実行されたあと、fallthroughで、
Case Bの節を実行する。
Case Cは実行されないので、その中のfallthroughは通過しない。
もしa=Cだったら、defaultも
実行される。

fallthrough.go
package main

func main () {
    a := "A" 
    switch a { 
    case "A":
        println("A")
        fallthrough
    case "B":
        println("B")
    case "C":
        println("C")
        fallthrough
    default:
        println("end")
    }   
}                                                                                                  

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0