1
所有for循环,我基本上看到如下所示:不同类型的for循环结构
for(int i = 0; i < thing.length; i++){
// Does this each iteration
}
但在我碰到一个项目工作(我认为是),针对不同类型的如下所示。有人可以向我解释这种类型的循环是如何工作的吗?它有名字吗?
Component[] squares = getComponents();
for (Component c : squares)
{
Square s = (Square) c;
// Set the color of the squares appropriately
int status = model.getOccupant(s.getRow(), s.getCol());
if (status == P1)
{
s.setColor(P1_COLOR);
}
else
{
s.setColor(BACKGROUND_COLOR);
}
}
你google一下? – shaun
如果你不知道它叫什么,很难谷歌的东西。但现在我知道了。谢谢,@Eran –