简单函数
func sum(x:Int,y:Int) ->Int{
return x+y
}
let number = sum(x: 5, y: 6)
print(number)
无返回值类型的函数
func sayHelloTo(name:String,world:String){
print("hello",name,world)
}
无参数函数
func sayHello(){
print("nothing")
}
多个返回值的函数
func Muete(num:[Int]) ->(max:Int,min:Int,sum:Int){
var max = num[0]
var min = num[0]
var sum = 0
for temp in num {
if temp>max {
max = temp
}
if temp<min {
min = temp
}
sum+=temp
}
return (max,min,sum)
}
网友评论