Conditional Statements (if-else)

Conditional statements help your program make decisions. Use if, else if, and else.

int age = 18;
if (age < 18) {
    System.out.println("You're underage.");
} else {
    System.out.println("You're an adult.");
}

Loops (for and while)

Loops let you repeat actions. Use for loops for a fixed number of iterations and while loops for conditions.

for (int i = 1; i <= 5; i++) {
    System.out.println("Iteration: " + i);
}
int count = 0;
while (count < 3) {
    System.out.println("Count: " + count);
    count++;
}