Recall & Review
beginner
What is a switch statement in Go?
A switch statement in Go lets you choose between many options based on the value of an expression. It is like asking multiple questions and running the code for the first true answer.
Click to reveal answer
beginner
How does Go's switch differ from if-else chains?
Go's switch is cleaner and easier to read than many if-else statements. It automatically breaks after a case runs, so you don't need to write break statements like in some other languages.
Click to reveal answer
beginner
What happens if no case matches in a Go switch?
If no case matches, and there is a default case, the default code runs. If there is no default, the switch does nothing and moves on.
Click to reveal answer
intermediate
Can a Go switch expression have multiple values in one case?
Yes! You can list multiple values separated by commas in one case. If the switch expression matches any of those values, that case runs.
Click to reveal answer
intermediate
What is a type switch in Go?
A type switch lets you check the type of an interface value. It helps you run different code depending on what kind of value you have.
Click to reveal answer
What keyword is used to run code when no other case matches in a Go switch?
✗ Incorrect
The 'default' case runs when no other case matches in a Go switch.
In Go, what happens after a case block runs in a switch statement?
✗ Incorrect
Go switch statements automatically break after a case runs, so no explicit 'break' is needed.
Which of these is a valid way to write multiple values in one case in Go switch?
✗ Incorrect
You separate multiple values with commas in one case, like 'case 1, 2, 3:'.
What does a type switch check in Go?
✗ Incorrect
A type switch checks the actual type of an interface value to run different code.
Which statement about Go switch is true?
✗ Incorrect
Go switch automatically breaks after a case runs; no manual 'break' is needed.
Explain how a switch statement works in Go and how it differs from if-else chains.
Think about how Go chooses which code to run based on a value.
You got /5 concepts.
Describe what a type switch is in Go and give an example of when you might use it.
Consider when you have a variable that can hold different types.
You got /5 concepts.