xcode - 如何在 Swift 中使用比较运算符分配 "bigger than but smaller than"?

标签 xcode swift variables if-statement

我想做这样的事情:

if (a < 10) {
    println("yes")
} else if (10 < a < 20) {
    println("no")
}

显然我做不到 (X < variable < Y)

抱歉,如果我没有很好地编辑它,希望你能理解我的问题。 谢谢。

最佳答案

第一个条件 a > 10。第二个条件 a < 20。所以你只需要使用“&&”运算符,意思是“和”,所以它需要同时满足这两个条件。

let a = 15

if a < 10 {
    println("yes")
} else if a > 10 && a < 20 {
    println("no")
}

关于xcode - 如何在 Swift 中使用比较运算符分配 "bigger than but smaller than"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30227907/

相关文章:

ios - 获取在 VNDetectTextRectanglesRequest 完成处理程序上的 VNImageRequestHandler 中使用的 cvPixelBuffer

ios - 无法在 Testflight 上更新配置文件

ios - 在字符串中查找数字并计算,插入字符串中(Swift)

swift - 如何快速获取多个音频的混合并将其保存为单个音频

python - 通过curl将变量传递到Flask端点

c++ - 如何声明已在类中声明的 char 变量的 Char 数组?

Java/Android - 存储许多变量的最有效方式

xcode - locationManager didFailWithError null phonegap 模拟器

xcode - Swift:按多个标准(权重)对数组进行排序

ios - 如何将 HKBloodType 枚举转换为字符串