Home »
Code Examples »
Golang Code Examples
Golang - Show the Duplicate Case Error in Switch Statement Code Example
The code for Show the Duplicate Case Error in Switch Statement
package main
import "fmt"
// Main function
func main() {
i := 1
switch i {
case 0, 1:
fmt.Println("Hello World")
fallthrough
case 0:
fmt.Println("Hello")
case 1:
fmt.Println("World")
default:
fmt.Println("Default it is.")
}
}
/*
Output:
./main.go:12:9: duplicate case 0 in switch
previous case at ./main.go:9:14
./main.go:14:9: duplicate case 1 in switch
previous case at ./main.go:9:17
*/
Code by IncludeHelp,
on February 28, 2023 16:07