swift case falling through

前端 未结 5 886
时光说笑
时光说笑 2020-12-07 21:30

Does swift have fall through statement? e.g if I do the following

var testVar = \"hello\"
var result = 0

switch(testVal)
{
case \"one\":
    result = 1
case         


        
5条回答
  •  盖世英雄少女心
    2020-12-07 22:15

    case "one", "two":
        result = 1
    

    There are no break statements, but cases are a lot more flexible.

    Addendum: As Analog File points out, there actually are break statements in Swift. They're still available for use in loops, though unnecessary in switch statements, unless you need to fill an otherwise empty case, as empty cases are not allowed. For example: default: break.

提交回复
热议问题