Introduction
The switch
statement is a conditional statement that allows you to execute different code blocks based on the value of an expression. It is a powerful tool that can simplify your code and make it more readable.
This tutorial is from open-source community. Access the source code
The switch
statement is a conditional statement that allows you to execute different code blocks based on the value of an expression. It is a powerful tool that can simplify your code and make it more readable.
In this challenge, you need to complete the switch
statement to print out the corresponding message based on the input value.
switch
statement must be used to solve the problem.default
case must be used to handle unexpected input values.$ go run switch.go
Write 2 as two
It's a weekday
It's after noon
I'm a bool
I'm an int
Don't know type string
In this challenge, you learned how to use the switch
statement to execute different code blocks based on the value of an expression. You also learned how to handle unexpected input values using the default
case.