Loops 检查无限while循环。我使用的是布尔变量
我正在使用以下代码:Loops 检查无限while循环。我使用的是布尔变量,loops,while-loop,boolean,using,infinite,Loops,While Loop,Boolean,Using,Infinite,我正在使用以下代码: boolean continueProcessing = true; boolean lastRecord = false; while (continueProcessing) //can it be changed to while (continueProcessing == true), what's the advantage { if(refListItemItr.hasNext() || lastRecord) { conti
boolean continueProcessing = true;
boolean lastRecord = false;
while (continueProcessing) //can it be changed to while (continueProcessing == true), what's the advantage
{
if(refListItemItr.hasNext() || lastRecord)
{
continueProcessing = true;
lastRecord = false;
}
else
{
continueProcessing = false;
}
if(continueProcessing)
{
lSynonymListType = objFactory.createSynonymListType();
}
}
我怀疑有一个无限循环的场景。我应该如何确认它没有发生。这将导致无限循环的原因是,您一直在检查下一项是否存在,但从未调用next()来检索它,因此内部指针不会移动,您只是在检查列表中是否有第一项 不管怎样,你把这件事搞得太复杂了。你应该做些什么
while (refListItemItr.hasNext()){
Object item = refListItemItr.next(); // change Object to the item's type
// Presumably actually do something with the item here, which currently you're not...
}
或者,更简单地说
for (Object o : refListItemItr){
// do stuff
}
在回答你的另一个问题时,while(continueProcessing)和while(continueProcessing==true)之间绝对没有区别。请格式化你的代码。这段代码看起来没有任何实际作用。。。你想在这里实现什么?另外,refListItemItr的类型是什么?实际上我还没有编写完整的代码。它相当大。只是想知道这个场景是否可以完全消除?