没有guard
let money = true
let idcard = true
func online2(age : Int,money:Bool,idcard:Bool){
if age >= 18 {
if money {
if idcard {
print("一起来开黑吖")
}else{
print("回去带身份证吧")
}
}else{
print("回去拿钱")
}
}else {
print("还未成年呢")
}
}
//调用
online2(age: age, money: money, idcard: idcard)
有guard
func online1(age : Int){
//判断年龄
guard age >= 18 else {
print("还未成年呢")
return
}
//判断是否有钱
guard money else {
print("回去拿钱")
return
}
//判断是否带了身份证
guard idcard else {
print("回去带身份证吧")
return
}
print("一起来开黑吖")
}
网友评论