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 for
loop used to iterate over arrays and any Iterable
, which includes any Collection
.
This is referred to as a for-each loop, as in: for each element of a list.
Read: for (MovingElement mElement : moveElems)
as _for each MovingElement
in the collection moveElems_
.
See: The For-Each Loop.
This is for-each
loop in Java.
For each element in Arraylist
(or) array.
The element will be assigned to MovingElement mElement which is scoped to the for loop .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With