🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)
🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)

🔧 Programmierung 🕛 vor 5 Monaten 3 Min Lesezeit
0

🚀 Day 24 of My Automation Journey – Looping Statements (While Loop)

↗ Quelle (dev.to)
🗣️ Stimme:



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




CODE
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




CODE
int i = 1;

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






📤 Output




CODE
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




CODE
int i = 1;

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






📤 Output




CODE
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




CODE
int i = 1;

while(i <= 10) {
if(i % 2 != 0) {
System.out.print(i + " ");
}
i++;
}






📤 Output




CODE
1 3 5 7 9






✅ Explanation



✔ i % 2 != 0 → odd numbers

✔ Even numbers skipped



🔍 Scenario 4: Multiplication Table (×5)

❓ Question



Print multiplication table of 5




CODE
int i = 1;

while(i <= 5) {
System.out.println(i + " * 5 = " + i * 5);
i++;
}






📤 Output




CODE
1 * 5 = 5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25






✅ Explanation



✔ Loop runs 5 times

✔ Multiplies i * 5



🔍 Scenario 5: Multiples of 3 AND 5

❓ Question



Print numbers divisible by both 3 and 5




CODE
int i = 1;

while (i <= 30) {
if (i % 3 == 0 && i % 5 == 0)
System.out.println(i);
i++;
}






📤 Output




CODE
15
30






✅ Explanation



✔ && → both conditions must be true

✔ Only multiples of 15 printed



🔍 Scenario 6: Multiples of 3 OR 5

❓ Question



Print numbers divisible by 3 OR 5




CODE
int i = 1;

while (i <= 10) {
if (i % 3 == 0 || i % 5 == 0)
System.out.println(i);
i++;
}






📤 Output




CODE
3
5
6
9
10






✅ Explanation



✔ || → any one condition true

✔ More numbers printed



🔍 Scenario 7: Multiple Conditions with if-else

❓ Question



Print different messages based on divisibility




CODE
int i = 1;

while (i <= 20) {

if (i % 3 == 0 && i % 5 == 0)
System.out.println(i + " multiply by both");

else if (i % 3 == 0)
System.out.println(i + " multiply by 3");

else if (i % 5 == 0)
System.out.println(i + " multiply by 5");

else
System.out.println(i);

i++;
}






📤 Output (Sample)




CODE
8
9 multiply by 3
10 multiply by 5
11
12 multiply by 3
13
14
15 multiply by both
16
17
18 multiply by 3






✅ Explanation



✔ Priority matters

✔ First matching condition executes



⚠️ Common Mistakes



❌ Forgetting i++ → Infinite loop 😱

❌ Wrong condition → loop never runs

❌ Using = instead of ==



🧠 Key Takeaways



✔ While loop checks condition first

✔ Used when number of iterations is unknown

✔ i++ is very important

✔ && → both conditions

✔ || → any one condition

✔ Can combine with if-else for complex logic



🏁 Conclusion



Today I learned how to use while loop effectively with conditions.



This is very useful in automation for:



✔ Repeating test steps

✔ Data-driven testing

✔ Iterating through elements



Step by step, I’m improving my Java logic for Selenium Automation 🚀



🤖 A Small Note



I used ChatGPT to help structure and refine this blog while ensuring the concepts remain aligned with my trainer’s explanations.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Sam Altman calls GPT-6 Astra rollout ‘messy’ as enterprise users wait for access
1 Quelle
Swiss government explores replacing Microsoft 365 with open-source software
1 Quelle
What continuous operational resilience looks like under DORA
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten 🚀 Day 24 of My Automation Journey – Looping Statements (While Loop)

Thematisch verwandte Begriffe: Automation, Journey, Looping, Statements · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...