聲明:
1> guard 必須使用在函數(shù)里面
2> guard 語句必須帶有else語句 語法如下:?
?當條件表達式為true時跳過else語句內容,執(zhí)行語句組內容?
?條件表達式為false時執(zhí)行else內容, 跳過語句一般為return、break、continue、throw(拋異常).
? let age = 18
if(age>=18){
"成年人"
}else{
"未成年人"
}
guard age >= 18 {
"未成年人"
return
}
聲明:
1> guard 必須使用在函數(shù)里面
2> guard 語句必須帶有else語句 語法如下:?
?當條件表達式為true時跳過else語句內容,執(zhí)行語句組內容?
?條件表達式為false時執(zhí)行else內容, 跳過語句一般為return、break、continue、throw(拋異常).
? let age = 18
if(age>=18){
"成年人"
}else{
"未成年人"
}
guard age >= 18 {
"未成年人"
return
}