-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForLoop2.java
More file actions
27 lines (25 loc) · 983 Bytes
/
ForLoop2.java
File metadata and controls
27 lines (25 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* b. for-each loop(Enhanced for loop).
* The for-each loop is used to traverse array or collection in java. It is easier to use
* than simple for loop because we don't need to increment value and use subscript notation.
* It works on elements basis not index. It returns element one by one in the defined variable.
* It was introduced in Java 5. It provides a simpler way to iterate through the elements of a
* collection or array. It is inflexible and should be used only when there is a need to iterate
* through the elements in sequential manner without knowing the index of currently processed element.
*
* Syntax:
* for(T element: Collection obj/ Array){
* //code to be executed.
* }
*
*
*/
public class ForLoop2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[] = {22,33,44,66};
for(int i:arr) {
System.out.println(i);
}
}
}