Skip to content
Learn Netverks

Lesson

Step 9/36 25% 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, patterns, and safety habits you need before advancing in C.

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

You will apply Control flow in contexts like: Kernels, drivers, embedded devices, and performance libraries used by other languages.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true).

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

Branch and loop with if, else, for, while, and do-while. C treats zero as false and any non-zero value as true.

if and else

if (score >= 60) {
    printf("pass\n");
} else {
    printf("retry\n");
}

Loops

for (int i = 0; i < 5; i++) {
    printf("%d\n", i);
}

C99 allows declaring the loop variable in the for header. Use break and continue like other C-family languages.

switch

switch works on integer types. Always include break unless fall-through is intentional.

Important interview questions and answers

  1. Q: Truth values in C?
    A: Zero is false; any non-zero is true—do not assume only 0 and 1 after arbitrary expressions.
  2. Q: Missing break in switch?
    A: Execution falls through to the next case—sometimes intentional, often a bug.

Self-check

  1. Which loop runs the body at least once?
  2. What value is considered false in an if condition?

Interview prep

Truth in C?

Zero is false; any non-zero is true—do not assume expressions yield exactly 0 or 1 unless normalized.

switch fall-through?

Missing break executes subsequent cases—document intentional fall-through with comments.

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 fallthrough?
  • for vs while?

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