如何编写数字与范围的比较?
1不在2-5之内
或
3在2-5之内
发布于 2009-02-28 05:44:27
它在Perl6
中甚至更好。
链式比较运算符:
if( 2 <= $x <= 5 ){
}
智能匹配操作员:
if( $x ~~ 2..5 ){
}
交界处:
if( $x ~~ any 2..5 ){
}
给予/当运营者:
given( $x ){
when 2..5 {
}
when 6..10 {
}
default{
}
}
发布于 2009-02-28 04:38:20
在Perl中:
if( $x >= lower_limit && $x <= upper_limit ) {
# $x is in the range
}
else {
# $x is not in the range
}
发布于 2009-02-28 04:42:47
在巴什:
$ if [[ 1 -gt 2 && 1 -lt 5 ]]; then echo "true"; fi
$ if [[ 3 -gt 2 && 1 -lt 5 ]]; then echo "true"; fi
true
https://stackoverflow.com/questions/597497
复制相似问题