| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

差分

ナビゲーションに移動 検索に移動
279 バイト追加 、 2021年1月18日 (月) 12:03
for i in 0 ... 10 {
switch i {
case 2, 4: // 列挙できる
print("twe,four\(i)") // breakがなくてもcaseブロック終了でswitchを抜ける
case 5:
print("five \(i)")
case 6:
break // break書いても良い case 7 ..< 9: // 範囲指定 print("7 <= i < 9: \(i)") fallthrough // break書いても良いfall through は明示することで可能 default: // 式がとりうる値を網羅していないとコンパイルエラー
print("other \(i)")
}
}
結果:
other 0
other 1
twe,four2
other 3
twe,four4
five 5
7 <= i < 9: 7
other 7
7 <= i < 9: 8
other 8
other 9
other 10
</pre>

案内メニュー