Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 581 Bytes

loops_iii.md

File metadata and controls

36 lines (29 loc) · 581 Bytes

Loops III

Counting indexes of elements is, while effective, a tad exhausting to do every time you want to loop through something.

~void main() {
String[] shirts = new String[] {
    "T-Shirt",
    "Polo Shirt",
    "Dress Shirt"
};

for (int i = 0; i < shirts.length; i++) {
    String shirt = shirts[i];

    System.out.println(shirt);
}
~}

This is where "for-each" loops come in.

~void main() {
String[] shirts = new String[] {
    "T-Shirt",
    "Polo Shirt",
    "Dress Shirt"
};

for (String shirt : shirts) {
    System.out.println(shirt);
}
~}