Swift 语言之控制流学习笔记
for循环
for-in(数组,集合,字典,字符串类似):
1 | for index in 1...5 { |
忽略对值的访问:
1 | let base = 3 |
for循环:
1 | for var index = 0; index < 3; ++index { |
while循环
while循环:
1 | var square = 0 |
do-while循环:
1 | let finalSquare = 25 |
条件语句
if语句:
1 | temperatureInFahrenheit = 90 |
switch语句:
1 | let someCharacter: Character = "e" |
范围匹配:
1 | let count = 3_000_000_000_000 |
元组:
1 | let somePoint = (1, 1) |
值绑定:
1 | let anotherPoint = (2, 0) |
where语句:
1 | let yetAnotherPoint = (1, -1) |
控制转移语句
continue语句:
1 | let puzzleInput = "great minds think alike" |
break语句:
1 | let numberSymbol: Character = "三" // Simplified Chinese for the number 3 |
fallthrough语句:
1 | let integerToDescribe = 5 |
带标签的语句:
1 | let finalSquare = 25 |