Back
I have an enum in Java for the cardinal & general directions:
public enum Direction { NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST}
public enum Direction {
NORTH,
NORTHEAST,
EAST,
SOUTHEAST,
SOUTH,
SOUTHWEST,
WEST,
NORTHWEST
}
How can I write a loop that iterates through each of these enum values?
Use values() on your enum:
Syntax:
for (Direction dir : Direction.values()) { // do your stuff}
for (Direction dir : Direction.values()) {
// do your stuff
31k questions
32.8k answers
501 comments
693 users