Control flow and functions
Decisions with if and switch, loops with for, and functions that return several values.
About 4 hours of study
Learning objectives
- Make decisions with if and switch
- Repeat work with the for loop
- Write and call functions
Lessons
- 1
Conditions and switch
Making decisions with if, else if and else, comparison and logical operators, the if statement with a short setup, and switch with several values per case or no value at all.
- 2
Loops with for
Go's only loop keyword, for, in its three forms: with a counter, with just a condition, and forever; plus break, continue, nested loops and range over a string.
- 3
Functions and multiple return values
Writing functions with parameters and results, returning several values, named results, variadic parameters, functions as values, closures, recursion and defer.
Module practice
- Go: Negative, zero or positiveEasy
- Go: Weekday or weekendMedium
- Go: Classify a triangleHard
- Go: Sums up to nEasy
- Go: Is it prime?Medium
- Go: Collatz steps and peakHard
- Go: Largest of threeEasy
- Go: Quotient and remainderMedium
- Go: GCD and LCMHard