Conditional Logic (if)
In Dart,
if statements work just like in other C-style languages.dart
The Modern switch (Dart 3.0+)
Wait! Dart 3.0 introduced a massively upgraded Switch system. It can now be used as an expression (returning a value) and supports pattern matching.
dart
Loops in Dart
Dart provides the standard loops you expect:
for: Best for a fixed number of iterations.for-in: The easiest way to iterate through a list.while: Runs as long as a condition is true.
dart
Assertions
During development, you can use
assert to verify that a condition is true. Assertions are ignored in production, so they have no performance cost for your users.dart
Summary
| Keyword | Description |
|---|---|
| if / else | Basic branching |
| switch | Multi-way branch (supports patterns in Dart 3+) |
| for-in | Iterating through collections |
| while | Basic loop with condition |
| break | Exit loop immediately |
| continue | Skip current iteration |
| Logic | Essential for app logic and UI states |
| Safety | Switches must be exhaustive if using Enums |
| Modern | Switch expressions and patterns make code very concise |
| Standard | Use for-in for almost all collection processing |
| Identity | Control flow returns no value except in switch expressions |