Skip to content
Learn Netverks

Lesson

Step 10/36 28% through track

control-flow

Control flow

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Control flow: the syntax, APIs, and habits you need before advancing in Java.

Teams ship Control flow on every Java codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Control flow in contexts like: Spring Boot APIs, banking systems, Android (with Kotlin), and batch/data pipelines on the JVM.

Write Java with a public class (lessons use Main), click Run on server—the dev runner runs javac then java; fix compile errors from stderr (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Java control flow matches C-family languages: if/else, switch, for, while, and enhanced for-each over arrays and collections.

if and switch

if (score >= 90) {
    grade = "A";
} else if (score >= 80) {
    grade = "B";
}

switch (day) {
    case "MON" -> System.out.println("Start week");
    case "FRI" -> System.out.println("Almost weekend");
    default -> System.out.println("Midweek");
}

Modern switch expressions (Java 14+) can return values with arrow syntax.

Loops

for (int i = 0; i < 3; i++) { }
for (String item : items) { }

Important interview questions and answers

  1. Q: switch on String since when?
    A: Java 7+ supports String in switch; use expressions in modern code.
  2. Q: break vs continue?
    A: break exits the loop; continue skips to the next iteration.

Self-check

  1. Write the enhanced-for loop syntax for a String[].
  2. When is a switch clearer than chained if-else?

Pitfall: Classic switch cases fall through without break—prefer arrow syntax (case X ->) in modern Java.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • switch break forget?
  • Enhanced for vs index?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump