Grokking Java Basics
0% completed
Java for-each Loop
The for-each loop in Java provides a simple way to iterate over elements of an array or a collection. It is designed to reduce the verbosity of code when you need to access each element sequentially. This loop is ideal when you don’t need to modify the elements or use the index for any computation.
Syntax
for (type variable : collection) { // Code block to execute for each element }
- type: The data type of the elements in the array or collection.
- variable: A temporary variable that holds the current element in the iteration.
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%