-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoop.java
More file actions
51 lines (43 loc) · 1.48 KB
/
Copy pathLoop.java
File metadata and controls
51 lines (43 loc) · 1.48 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Assignment1;
public class Loop {
public static void main(String[] args) {
System.out.println("// -------- For LOOP --------//");
for (int a = 1; a <= 5; a++) {
System.out.println(a);
}
System.out.println("// -------- While LOOP --------//");
int i = 5;
while (i > 0) {
System.out.println(i);
i--;
}
System.out.println("// -------- Do-While LOOP --------//");
int b = 1;
do {
System.out.println(b);
b++;
} while (b <= 5);
System.out.println("//-------- Infinite LOOP (commented to avoid crash) --------//");
System.out.println("/* while (true) {");
System.out.println(" System.out.println(\"This is an infinite loop\");");
System.out.println("} */");
System.out.println("// -------- Break Statement --------//");
for (int c = 1; c <= 10; c++) {
if (c == 5)
break;
System.out.println(c);
}
System.out.println("//-------- Continue Statement --------//");
for (int d = 1; d <= 5; d++) {
if (d == 3)
continue;
System.out.println(d);
}
System.out.println("//-------- Even Numbers --------//");
for (int e = 1; e <= 50; e++) {
if (e % 2 == 0) {
System.out.println(e);
}
}
}
}