Loop Task Day

🔁 Programming Session 3:

☕ Let’s Practice Loops with Number Patterns in Java!


🔢 Task 1: Print Numbers from 1 to 5

int i = 1;
while (i <= 5) {
    System.out.print(i + " ");
    i++;
}

Output:

1 2 3 4 5


🔢 Task 2: Print Odd Numbers – 1 3 5 7 9

int i = 1;
while (i <= 9) {
    System.out.print(i + " ");
    i += 2;
}

Output:

1 3 5 7 9


🔢 Task 3: Print Multiples of 3 – 3 6 9 12 15

int i = 3;
while (i <= 15) {
    System.out.print(i + " ");
    i += 3;
}

Output:

3 6 9 12 15


🔢 Task 4: Print Multiples of 4 – 4 8 12 16 20

int i = 4;
while (i <= 20) {
    System.out.print(i + " ");
    i += 4;
}

Output:

4 8 12 16 20


🔢 Task 5: Print Multiples of 5 – 5 10 15 20 25

int i = 5;
while (i <= 25) {
    System.out.print(i + " ");
    i += 5;
}

Output:

5 10 15 20 25


✅ Summary – What I Learned Today

  • while loop in Java checks a condition and repeats the block.
  • Understanding the start value and step size is key to pattern creation.
  • Loops help reduce repetitive code and make programs efficient.
  • Practice makes patterns easy! 🔂