-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoops.java
37 lines (32 loc) · 996 Bytes
/
Loops.java
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
28
29
30
31
32
33
34
35
36
37
class Loops
{
public static void main(String arg[])
{
int Arr[] = {10,20,30,40};
int iCnt = 0;
System.out.println("Traversal of array using for loop");
for(iCnt = 0; iCnt < Arr.length; iCnt++) //same in c, c++,java
{
System.out.println(Arr[iCnt]);
}
System.out.println("Traversal of array using while loop");
iCnt = 0;
while(iCnt < Arr.length) //Same in c,c++,java
{
System.out.println(Arr[iCnt]);
iCnt++;
}
System.out.println("Traversal of array using do while loop");
iCnt = 0;
do //Same in c,c++,java
{
System.out.println(Arr[iCnt]);
iCnt++;
}while(iCnt < Arr.length);
System.out.println("Traversal of array for-each while loop");
for(int iNo : Arr) // only in java
{
System.out.println(iNo);
}
}
}