Control Flow in Dart
Control Flow teaches your program to decide and repeat.
In this chapter, you will:
- make decisions with
if,else if,switchand switch expressions - repeat work with
for,whileanddo-whileloops - stop or skip rounds with
breakandcontinue - write your own functions, with parameters, return values, closures and recursion
What each lesson covers:
- Conditional Statements: How a program makes decisions with if, else, else if, nested conditions, switch statements and switch expressions.
- Loops: How to repeat work with for, while and do-while loops, how to stop or skip rounds, nested loops, and looping over a list.
- Functions: How to write and call functions, return values, positional, optional and named parameters, arrow and anonymous functions, closures, recursion and scope.
This chapter has 3 lessons. Plan on about 53 minutes, with 9 exercises to check what you learned. Every example is real Dart code: change it, run it again and compare the output, which is the fastest way to learn how each feature behaves.
Simple lesson: finish this chapter and you can write programs that choose, repeat and reuse code.
Lessons in this section
- Conditional Statements
How a program makes decisions with if, else, else if, nested conditions, switch statements and switch expressions.
- Write if, if else and else if chains
- Use switch statements and switch expressions
- Pick the right kind of decision for the job
- Loops
How to repeat work with for, while and do-while loops, how to stop or skip rounds, nested loops, and looping over a list.
- Write for, while and do-while loops
- Use break and continue
- Loop over a list with for-in and forEach
- Functions
How to write and call functions, return values, positional, optional and named parameters, arrow and anonymous functions, closures, recursion and scope.
- Define and call functions that return values
- Use positional, optional and named parameters
- Use arrow functions, callbacks, closures and recursion