问题描述
而我在eclipse中工作Java时遇到了许多次, (recsFinished = true)
实际上我想要
while(recsFinished == true)
一个很简单的错误,但它发生在我身上,它完全抛弃了程序。它的原因是因为Eclipse在写入赋值而不是等式方程时甚至不会发出警告。这使我相信存在一个存在赋值方程的while循环的原因,但是为什么?我不能想到一个用途!
这样的作业在C和C ++中很受欢迎(特别是在 if
statments),并发现自己也是Java的一部分。
一些民间人将文字放在左边: while(true == recsFinished)
而是我试图建议你采用这种编程风格,只是我个人觉得它混淆。如果意外使用 =
,则会发出编译器错误。
请注意虽然与 true
的比较是多余的。完全删除它,并使用 while(recsFinished)
。
I've been punked numerous times while working on Java in eclipse when I write a while loop like so:
while (recsFinished = true)
When in reality I wanted
while (recsFinished == true)
It's a pretty simple mistake, but it happens to me a lot and it totally throws off the program. And the reason it does is because Eclipse doesn't even throw up a warning when I write the assignment as opposed to the equality equation. This leads me to believe there has to be some reason for a while loop with an assignment equation to exist, but why? I can't think of a single use!
Such assignments are popular in C and C++ (particularly within if
statments) and have found themselves part of Java too.
Some folk put the literal on the left hand side: while (true == recsFinished)
instead and I'm tempted to suggest that you adopt this programming style only that I personally find it obfuscating. This will issue a compiler error if =
is used by accident.
Note well though that comparison to true
is redundant. Drop it entirely and use while (recsFinished)
instead.
这篇关于是否有任何原因Eclipse在while循环中显示赋值变量有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!