Swift语言可以帮助你在if-else语句内使用if-else语句。嵌套的if-else语句也可以在Swift的switch语句中使用。
例:
let n1 = 10, n2 = 22, n3 = 25
if 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)
}
}
输出
The largest number is 25
评论前必须登录!
注册