「Swift」switch文にタプルの複数条件を判定する

書式
let タプル名=(条件値1,条件値2,条件値3)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
switch タプル名{
case ( 値1,値2,値3):処理コード
}
switch タプル名{ case ( 値1,値2,値3):処理コード }
switch タプル名{
  case ( 値1,値2,値3):処理コード 
}

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//タプルに複数の条件を定義 条件1 条件2
let tpe = (308, "study", "arkgame")
//switch文にタプルを使用
switch tpe {
case (308, "Study","game"):
print("東京 条件を満たしない")
case (308, "study","arkgame"):
print("茨城県 条件を満たす")
case (308, "tudy","game"):
print("埼玉")
default:
print("千葉県")
}
//タプルに複数の条件を定義 条件1 条件2 let tpe = (308, "study", "arkgame") //switch文にタプルを使用 switch tpe { case (308, "Study","game"): print("東京 条件を満たしない") case (308, "study","arkgame"): print("茨城県 条件を満たす") case (308, "tudy","game"): print("埼玉") default: print("千葉県") }
//タプルに複数の条件を定義 条件1 条件2
let tpe = (308, "study", "arkgame")

//switch文にタプルを使用
switch tpe {
  case (308, "Study","game"):
     print("東京 条件を満たしない")
  case (308, "study","arkgame"):
    print("茨城県 条件を満たす")
  case (308, "tudy","game"):
    print("埼玉")
  default:
    print("千葉県")
}

実行結果
$ swift tpp.swift
茨城県 条件を満たす

Swift

Posted by arkgame