-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopBasics.java
More file actions
46 lines (36 loc) · 1.12 KB
/
Copy pathLoopBasics.java
File metadata and controls
46 lines (36 loc) · 1.12 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
package loops;
public class LoopBasics {
public static void main(String[] args) {
// ===== while Loop =====
// int counter = 1;
// while(counter <= 100) {
// System.out.println("Hello World!");
// counter++;
// }
// ===== for Loop =====
// for(int i = 1; i <= 10; i++) {
// System.out.println("Hello World!");
// }
// ===== do-while Loop =====
// int counter = 1;
// do {
// System.out.println("Hello World!");
// counter++;
// } while (counter <= 10);
// ===== Break Statement =====
// for (int i = 1; i <= 5; i++) {
// if(i == 3) {
// break; // Exit the loop when i is 3
// }
// System.out.println(i);
// }
// System.out.println("Out of the loop");
// ===== Continue Statement =====
for (int i = 1; i <= 5; i++) {
if(i == 3) {
continue; // Skip 3 and continue with the next iteration
}
System.out.println(i);
}
}
}