* Basic and Advanced Loops in Java
public class LoopExamples {
public static void main(String[] args) {
// 1. Basic Loops
// a) For Loop
for (int i = 0; i < 5; i++) {
System.out.println("For Loop: " + i);
// b) While Loop
int j = 0;
while (j < 5) {
System.out.println("While Loop: " + j);
j++;
// c) Do-While Loop
int k = 0;
do {
System.out.println("Do-While Loop: " + k);
k++;
} while (k < 5);
// 2. Advanced Loops
// a) Enhanced For Loop (For-Each Loop)
int[] numbers = {1, 2, 3, 4, 5};
for (int num : numbers) {
System.out.println("Enhanced For Loop: " + num);
}
// b) Infinite Loop (Use with caution)
/*
while (true) {
System.out.println("Infinite Loop");
*/
// c) Nested Loops
for (int a = 1; a <= 3; a++) {
for (int b = 1; b <= 3; b++) {
System.out.println("Nested Loop: " + a + "," + b);