I’m doing an assignment that involves a board. The base code is given for us to modify, but I don’t understand what the : in the parameters of the for() means. Does it go through all the board (the ArrayList)?
private ArrayList<MovingElement> moveElems = new ArrayList<MovingElement>();
for (MovingElement mElement : moveElems) {
mElement.step();
}
This is a special form of the
forloop used to iterate over arrays and anyIterable, which includes anyCollection.This is referred to as a for-each loop, as in: for each element of a list.
Read:
for (MovingElement mElement : moveElems)as _for eachMovingElementin the collectionmoveElems_.See: The For-Each Loop.