如果要简化语句,该如何?
How can this if statement be simplified?
我正在使用clion IDE来编码我的C 项目。有时,IDE试图比我更聪明,并给我建议。在代码检查期间(通过CLION(有一个简单的问题。它说,即使我认为这是我能想到的最简单的形式,也可以简化以下代码:
代码:
if (node.first >= 0 && node.first <= 45 &&
node.second >= 0 && node.second <= 30)
return true;
else
return false;
假设节点是类型std::pair<int, int>
我从Clion IDE获得的建议如下:
代码检查评论:
Inspection info: This inspection finds the part of the code that can be simplified, e.g. constant conditions, identical if branches, pointless boolean expressions, etc.
您认为这可以简化吗?
clion暗示您这个位...
if (node.first >= 0 && node.first <= 45 &&
node.second >= 0 && node.second <= 30)
return true;
else
return false;
可以重新编写为
return node.first >= 0 && node.first <= 45 &&
node.second >= 0 && node.second <= 30;
由于在控制语句中用作条件的表达式显然具有自然转换为true和false。
相关文章:
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- 如果 else 语句不断循环
- 如果中的多个语句是否与多个 if 相同?
- 如果条件不相关,我应该更喜欢两个 if 语句而不是 if-else 语句吗?
- 如果语句逻辑不正确
- 如果仍然不满足要求,如何使 if 语句重复?
- 如果 else 语句使用大写和小写字母
- 如果不是多个语句,请使用 if 语句
- 如果语句不包括文本行?
- 如果语句不会在 do - while 循环中运行
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- C++ 访问 if 语句(如果它们在 for 循环中)
- 如果 constexpr语言 - 为什么完全检查丢弃的语句?
- 如果验证容器的大小并在同一条件语句下访问元素,这是很好的做法吗?
- 如果语句错误地读取字符串,则始终在第一个条件返回
- 我如何在一个 if 语句中声明所有数字我尝试通过其他方式声明所有数字,如果一个接一个,但似乎代码有逻辑错误
- 如果 GPA 计算器的语句问题
- 如果 i<=number-1,那么 i 的最大值应该是 number-1,那么 number%1==0 或 i==number 语句如何为真?
- switch语句:如果输入不是数字(1到9)或字母(a到z)输出<<“错误”?C++
- 请帮助我使用if语句c++:如果某个值增加0.10,请执行以下操作: