Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 617 Bytes

File metadata and controls

39 lines (30 loc) · 617 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];

    IO.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) {
    IO.println(shirt);
}
~}