Java Loops Cheat Sheet/Enhanced for (for-each)

Iterate values without index

Section: Enhanced for (for-each)

Enhanced for (for-each)

java
java
for (String s : list) {\n  System.out.println(s);\n}
Explanation

Use for-each when you don’t need the index.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Enhanced for (for-each)
Basic for loop
Loop from 0..4
OpenIn sheetjava2 tag match
while loop
OpenIn sheetjava2 tag match
do-while loop
Executes body at least once
OpenIn sheetjava2 tag match