Swift嵌套if-else语句用法示例

Swift语言可以帮助你在if-else语句内使用if-else语句。嵌套的if-else语句也可以在Swift的switch语句中使用。
例:

let n1 = 10, n2 = 22, n3 = 25if n1 > = n2 { if n1 > = n3 {print("The largest number is ", n1) } else {print("The largest number is ", n3) }}else { if n2 > = n3 {print("The largest number is ", n2) } else {print("The largest number is ", n3) }}

【Swift嵌套if-else语句用法示例】输出
The largest number is 25

    推荐阅读