Skip to content
Learn Netverks

Lesson

Step 9/36 25% through track

control-flow-go

Control flow

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Control flow: the syntax, patterns, and safety habits you need before advancing in Go.

Coroutines replace callback hell on Android and in Ktor—structured concurrency is interview-critical.

You will apply Control flow in contexts like: Kubernetes ecosystem tools, cloud APIs, and CLI utilities.

Write Go in main.go with package main and func main(), click Run on server—the dev runner runs go run main.go; use fmt.Println for output (requires Go toolchain; LEARNING_RUNNER_ENABLED=true).

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

Go control flow is C-like: if, for, and switch. There is no while keyword—loops use for only. Parentheses around conditions are optional but braces are required.

if and for

if count > 0 {
    fmt.Println("positive")
}
for i := 0; i < 3; i++ {
    fmt.Println(i)
}

if may include a short statement before the condition: if err := f(); err != nil { ... }—common in Go error handling.

switch

switch does not fall through by default (no implicit break). Use fallthrough explicitly when needed. Switch works on types in type switches later.

Important interview questions and answers

  1. Q: while loop in Go?
    A: Use for condition { }—there is no separate while keyword.
  2. Q: Does switch fall through?
    A: No by default—each case breaks automatically unless fallthrough is used.

Self-check

  1. Write a for loop that prints 0, 1, 2.
  2. What keyword breaks out of a switch case automatically?

Tip: Only for loops exist—for {} is the while loop; braces are mandatory even for one-line bodies.

Interview prep

while in Go?

Use for condition { }—there is no separate while keyword.

switch fallthrough?

Cases break automatically; use explicit fallthrough when needed.

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

  • No while loop?
  • switch no fallthrough?

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