In Go, the `switch` statement allows you to check multiple conditions. If you want to match more than one condition in a single case, you can use a **comma-separated list** of conditions within that case.
### **Example: Using Two Conditions in One Case**
Let’s say you want to check whether a number is either 2 or 3, and if so, print a message. You can do it like this:
“`go
package main
import “fmt”
func main() {
num := 2
switch num {
case 1:
fmt.Println(“Number is 1”)
case 2, 3:
fmt.Println(“Number is either 2 or 3”)
case 4:
fmt.Println(“Number is 4”)
default:
fmt.Println(“Number is unknown”)
}
}
“`
### **Explanation**:
– In the `switch` statement, the `case 2, 3` condition will match if the value of `num` is either 2 or 3.
– The `fmt.Println(“Number is either 2 or 3”)` will be executed when the `num` is either 2 or 3.
### **Output:**
“`
Number is either 2 or 3
“`
### **Key Notes**:
– You can add as many conditions as needed in the same `case` by separating them with commas.
– The conditions will be evaluated as a single group, and if any one of them matches the value being tested, the case block will execute.
This approach works for any type of condition or expression in a `switch` statement.
