for (int[] row : table) {
for (int value : row) {
System.out.print(value + "\t");
}
System.out.println();
}
⨠This loop automatically iterates through each row and each value without using indices!
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
// Access using indices
table[i][j] = ...
}
}
â
Gives you access to indices (i, j)
â
Can modify array elements
for (int[] row : table) {
for (int value : row) {
// Direct access to values
System.out.print(value);
}
}
â
Cleaner, more readable
â
No indices to manage
â Cannot modify array elements
â No direct index access
for (int[] row : table) - Gets each entire row array one by onefor (int value : row) - Gets each value in the current row one by one