所以我有这些代码,而且我的for循环有问题。
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent event)
{
if (TownStones.blockPistons)
{
List<Block> pushedBlocks = event.getBlocks();
Material theMaterial = null;
int end = TownStones.blocks;
boolean done = false;
if (pushedBlocks != null) {
for (Iterator localIterator = pushedBlocks.iterator(); localIterator.hasNext(); !done)
{
Block theBlock = (Block)localIterator.next();
theMaterial = theBlock.getType();
done = false;
int i = 0; continue;
if (theMaterial == Material.getMaterial(TownStones.blockType[i]))
{
event.setCancelled(true);
done = true;
}
else if (i > end)
{
done = true;
}
i++;
}
}
}
}
Intellij Idea告诉我!done
不是声明
答案 0 :(得分:5)
那是因为!done
不是声明。问题是你的循环:
for (Iterator localIterator = pushedBlocks.iterator(); localIterator.hasNext(); !done)
这读作“开始,声明localIterator
并将其设置为pushedBlocks.iterator()
,然后在迭代器具有更多元素时继续”。 !done
没有语义含义。将for循环重写为:
for (Iterator localIterator = pushedBlocks.iterator(); localIterator.hasNext() && !done;)
答案 1 :(得分:2)
Java for
循环必须符合
for (initialization; termination; increment) {
statement(s)
}
式。 !done
不是有效的增量语句。请参阅
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html
有关如何使用for
循环的介绍。