- 01Setting up (what you'll need)
- 02Your first output (print)
- 03Variables and types (var and annotations)
- 04Null safety (? and !)
- 05Branching (the if statement)
- 06Repeating (the for loop)
- 07Writing your own function
- 08Repeating (the while loop)
- 09Working with lists (List)
- 10Working with maps (Map)
- 11Classes (object orientation)
- 12Constructors
- 13Inheritance
- 14Named arguments
- 15Asynchronous work (Future, async, await)
- 16Working with strings
- 17The switch statement
- 18The ternary operator
- 19Extension methods
- 20[Project] Build a small inventory system
Repeating (the for loop)
This lesson covers looping in Dart with a for statement.
Writing for (init; condition; update) { ... } repeats a block a fixed number of times.
The sample code writes for (int i = 1; i <= 5; i++) to print the numbers 1 through 5 in order.
A common early stumble is an off-by-one count caused by how the condition is written. Keep the difference between i <= 5 and i < 5 in mind so you get exactly the number of repetitions you meant.
In professional work, for loops are used constantly to process every element of a list, and the for-in form covered in the next lesson is just as common.
๐งช This site can't compile or run Dart directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
