如何测试变量是否在某个范围内?
我正在目标 c 中制作 if 语句,并且想知道是否可以测试变量是否不在值 x 和值 y 的范围内。例如,类似以下内容:
// test if float variable (called varFloat) is not in between 10.5 and 30.5
If (10.5 <! varFloat <! 30.5) {
doStuff();
}
我尝试了上面的代码,但它似乎不起作用,而且我什至不确定 运算符是否退出。非常感谢任何帮助。谢谢!
I'm making an if statement in objective c and would like to know if it's possible to test if a variable is not in the range of value x and value y. For example, something that goes along the lines of:
// test if float variable (called varFloat) is not in between 10.5 and 30.5
If (10.5 <! varFloat <! 30.5) {
doStuff();
}
I tried that code above and it doesn't seem to work, and I'm not even sure if the <!
operator exits. Any help is much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,如果某个值小于下限或大于上限,则该值不在范围内。
if ( var < x || var > y )
您可能会找到 C 和 C++ 中的运算符很有用。
Sure, a value is not in a range if it is less than the lower bound or greater than the upper bound.
if ( var < x || var > y )
You might find a list of operator in C and C++ useful.