Learn / Java / Control Flow

Beginner 15 min

Control Flow

if/else, for, while, and enhanced for-each loops.

What you will learn

  • Write if/else chains
  • Use for and while
  • Iterate arrays with for-each
java
int[] scores = {88, 92, 75};
for (int s : scores) {
    if (s >= 90) {
        System.out.println("A");
    } else {
        System.out.println("pass");
    }
}

Try it yourself

Print numbers 1–10, skipping 5.