【发布时间】:2018-05-24 19:25:16
【问题描述】:
我正在尝试将多个变量与一个表达式进行比较,如下所示:
if 1 <= x && x <= 5 &&
1 <= y && y <= 5 &&
1 <= z && z <= 5 {
// Code to run if true
}
我找到了question related to comparing a variable to multiple specific values,这不是我想要的,因为它不是不等式中的比较。
有什么办法可以缩短这个吗?
例如,缩短像 1 <= x && x <= 5 这样的不等式,或者让我能够以其他方式轻松比较 x、y 和 z?
【问题讨论】:
标签: ios swift comparison-operators