Lektion 4 af 10
Loops
Java understøtter for, while, do...while og enhanced for-loops. Enhanced for er god til arrays og collections.
JAVA
String[] fruits = {"apple", "banana", "cherry"};
// Standard for
for (int i = 0; i < fruits.length; i++) {
System.out.println(fruits[i]);
}
// Enhanced for (for-each)
for (String fruit : fruits) {
System.out.println(fruit);
}