for Loops
for has init, condition and update. The enhanced for walks arrays and lists.
Example
public class Main {
public static void main(String[] args) {
for (int i = 0; i < 3; i++) System.out.print(i + " ");
int[] a = {10, 20};
for (int v : a) System.out.print(v + " ");
System.out.println();
}
}Result
0 1 2 10 20
Exercise
Enhanced for.
for (int v a)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.