需要格式化逻辑函数的帮助——括号
我有一个 while 循环,其条件是两个语句的合取,其中一个语句包含嵌套的 OR。我找不到任何围绕运算符或使用括号组织语句的标准方法。请记住,实际语句比“a”长,例如“Math.Pow(double,exponent)*Math.Pow(Math.SQRT(double)),exponent)”,否则第二个版本将是明显的选择。关于如何编写此代码以便其他程序员发现它最容易阅读的正确方法有什么建议吗?
while
(
(
(a > b)
||
(
(
(a > d)
||
(
(p < q)
||
(r < s)
)
)
)
)
&& t < y
)
{
g = g + 0.25;
}
或者
while (((a > b) || (((a > d) || ((p < q) || (r < s))))) && t < y)
{
g = g + 0.25;
}
I have a while loop whose condition is a conjunction of two statements, one of which contains nested ORs. I couldn't find any standard method of organizing the statements around the operators or using parentheses. Keep in mind that the actual statements are longer than 'a', for example 'Math.Pow(double,exponent)*Math.Pow(Math.SQRT(double)),exponent)', otherwise the second version would be the obvious choice. Any suggestions on the proper way to write this so another programmer would find it easiest to read?
while
(
(
(a > b)
||
(
(
(a > d)
||
(
(p < q)
||
(r < s)
)
)
)
)
&& t < y
)
{
g = g + 0.25;
}
OR
while (((a > b) || (((a > d) || ((p < q) || (r < s))))) && t < y)
{
g = g + 0.25;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将它们放入具有说出名称的方法中,并在 while 循环中使用这些方法。其他的都是无法维护的!
Put them into methods with speaking names and use those methods in your while loop. Everything else is unmaintainable!