//如果想从一个case语句中跳到下一个case语句,可用关键字“fallthrough”
findAnswer: form in 1...300{
for n in 1...300{
ifm*m*m*m-n*n==15*m*n{
print(m,n)
break findAnswer
}
}
}
let point=(3,3)
switch point{
caselet (x,y) where x == y:
print("It's on the line x==y")
caselet (x,y) where x == -y:
print("It's on the line x==-y")
caselet (x,y):
print("It's just an ordinary point")
print("The point is (\(x),\(y))")
}
let age = 18ifcase10...19 = age{
print("You're a teenage.")
}
ifcase10...19 = age , age >= 18{
print("You're a teenage and in a college!")
}
let vector=(4,0)
ifcase ( let x, 0 ) = vector, x > 2 && x < 5{
print("It's the vector!")
}
forcaselet i in1...100 where i % 3 == 0{
print(i)
}
func buy(money: Int , price: Int , capacity: Int , volume: Int){
if money >= price{
if capacity >= volume{
print("I can buy it!")
print("\(money-price) Yuan left")
print("\(capacity-volume) cubic meters left")
}else{
print("No enough capacity")
}
}else{
print("Not enough money")
}
}
func buy2( money: Int , price: Int , capacity: Int , volume: Int){
guard money >= price else{//保证money >= price 否则输出print("Not enough moeney")
return
}
guard capacity >= volume else{//保证capacity >= volumeprint("Not enough capacity")
return
}
print("I can buy it!")
print("\(money-price) Yuan left.")
print("\(capacity-volume) cubic meters left")
}