Go TutorialLesson 14Free preview
Go Switch
This lesson is part of Go · All levels
Summary
This lesson discusses switching as a neat way to handle many conditions in Go. Every case doesn't need a break because Go doesn't do an automatic fallthrough, and you can write multiple values into one case. Go also supports unconditional switches that work like if-else chains, as well as fallthrough keywords when trying to force the next execution case.
Key points
- Switch case in Go does not automatically fall to the next case (without automatic break)
- One case can contain several values separated by a comma
- The switch without the expression functions as an if-else if sequence.
- Fallthrough forced the next execution of the contents of the case
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.