Skip to content

Commit d9d9eb3

Browse files
committed
feat: Print array elements using enhanced for-each loop
🧠 Logic: - Declare an integer array with predefined values. - Use a for-each loop to iterate through each element. - Print each element directly without using index-based access. Signed-off-by: Somesh diwan <[email protected]>
1 parent 24f6888 commit d9d9eb3

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Section8LoopAB/src/ForLoopAB4.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ public static void main(String[] args) {
1010
}
1111

1212
/*
13-
The for-each loop (also known as the enhanced for loop) in Java is used to traverse elements of arrays or collections in a simplified and readable way.
14-
It eliminates the need for managing an index manually and works well when you just need to access each element, rather than modifying the array or list.
13+
The for-each loop (also known as the enhanced for loop) in Java is used to traverse elements of
14+
arrays or collections in a simplified and readable way.
15+
16+
It eliminates the need to manage an index manually and works well when you just need to access each element,
17+
rather than modifying the array or list.
1518
1619
for (dataType element : arrayOrCollection) {
1720
Body of the loop
1821
You can use 'element' directly in the loop
1922
}
20-
21-
*/
23+
*/

0 commit comments

Comments
 (0)