您的位置:首页 > 移动开发 > Swift

swift 系统学习 03 三目 区间运算符 开区间 闭区间 和三目类似的还有一个空合/聚合运算符

2017-03-01 14:10 363 查看
/*
* 本节内容:
* 1.除法 %
* 2.&& ||
* 3.三目
* 4.区间运算符
*/

let imZero = 30
let imIntOne = 10.5
imIntOne / Double(imZero)

// Swift2.2的语法
// let result = 10 % 2.5
// Swift3.0
let result = 10.0.truncatingRemainder(dividingBy: 2.2)

// Swift3.0弃用++ --
var increment = 10
increment += 1

// 登录方式一:
var isUserNameOK = false
var isPasswordOk = false
// 登录方式二:
var isPhoneNumberOK = true
var isPhoneCodeOK   = false

if (isUserNameOK && isPasswordOk) || (isPhoneNumberOK && isPhoneCodeOK) {
print("Login Successed!")
} else {
print("Login Failed!")
}

// 三目
let batteryCapacity = 48
let batteryColor = batteryCapacity <= 20 ? UIColor.yellow : UIColor.green

/*
* 区间运算符Range Operator
* 1.闭区间运算符: x...y
* 2.开区间运算符: x..<y
*/
for index in 1...10 {
print("index is \(index)")
}
for index in 1..<10 {
print("index * index is \(index * index)")
}

// 了解数组: 相同类型
let courses = ["Objective-C", "JavaScript", "Swift", "C", "Java", "Ruby"]
for index in 0..<courses.count {
print("课程名字: \(courses[index])")
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐