🚀 Day 24 of My Automation Journey – Looping Statements (While Loop)
Today I explored Looping Statements in Java, especially the while loop. Loops are very important because they help us repeat a task multiple times without writing duplicate code. 🔹 What is a Loop?...

Source: DEV Community
Today I explored Looping Statements in Java, especially the while loop. Loops are very important because they help us repeat a task multiple times without writing duplicate code. 🔹 What is a Loop? 👉 A loop is used to execute a block of code repeatedly based on a condition. 🔁 Types of Loops in Java ✔ While Loop ✔ For Loop ✔ Do-While Loop 👉 Today focus: While Loop 🔹 While Loop Syntax while(condition) { // code } ✔ Condition is checked first ✔ If true → executes ✔ If false → stops 🔍 Scenario 1: Print same number multiple times ❓ Question Print 1 five times int i = 1; while(i <= 5) { System.out.print(1 + " "); i++; } 📤 Output 1 1 1 1 1 ✅ Explanation ✔ Loop runs 5 times ✔ Always prints 1 🔍 Scenario 2: Print numbers from 1 to 5 ❓ Question Print numbers from 1 to 5 int i = 1; while(i <= 5) { System.out.print(i + " "); i++; } 📤 Output 1 2 3 4 5 ✅ Explanation ✔ i increases each time ✔ Prints updated value 🔍 Scenario 3: Print odd numbers ❓ Question Print odd numbers from 1 to 10