3. Conditions and Loops
TL;DR (5 lines)
- Read the core idea first.
- Understand one concept at a time.
- Run small examples.
- Fix errors early.
- Move to next chapter only when clear.
Frequent mistakes
- Skipping prerequisites.
- Reading without trying examples.
- Fixing too many errors at once.
Prerequisites: book/poche/02-variables-and-types.html. See also: book/chapters/07-control.html.
Goal
Choose a path (if) and repeat an action (loop/for).
Example
entry main at app/demo {
let n: int = 3
if n > 0 {
return 1
}
return 0
}
Why it matters
Flow control is the central logic of a program.
Quick check
What output do you get if n = 0?
Try this
- Edit condition.
- Test 3 input values.
- Note the exits.
If you're stuck
Always write the nominal case first, then the limiting case.
Mini quiz
- What is the main goal of this chapter?
- Which concept is most important?
- What will you try right now?
See also
Next best action
Apply one idea from this chapter in a tiny example, then continue.