Java Logics: If else, for, foreach, while and do while
If-Else
if (age >= 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
For Loop
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
Foreach Loop
for (String item : items) {
System.out.println(item);
}
While and Do-While
A while loop checks its condition before running; a do-while loop runs its body at least once before checking the condition.
while (count < 5) { count++; }
do { count++; } while (count < 5);
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.
.png)