For Loops
A for loop has an initializer, a condition and an update. The for-each loop walks through every element of an array or collection without an index.
Example
for (int i = 0; i < 3; i++) {
System.out.println("i = " + i);
}
String[] names = {"Ada", "Tunde", "Zainab"};
for (String n : names) {
System.out.println(n);
}Result
i = 0 i = 1 i = 2 Ada Tunde Zainab
Exercise
Walk through each item.
for (String n names) {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.