Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tour: commas and semicolons in switch case #1669

Open
adriancuadrado opened this issue Nov 18, 2024 · 0 comments
Open

tour: commas and semicolons in switch case #1669

adriancuadrado opened this issue Nov 18, 2024 · 0 comments

Comments

@adriancuadrado
Copy link

Context: https://go.dev/tour/flowcontrol/10

In https://go.dev/tour/flowcontrol/10 we have an example of an if statement with semicolons in the condition. It would be nice to explain that this also works with switch.

Also, we could add an example with commas in a case to demonstrate another way to write cases.

We could replace the code in https://go.dev/tour/flowcontrol/10 with this:

package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println("When's Saturday?")
	today := time.Now().Weekday()
	switch saturday := time.Saturday; saturday {
	case today + 0:
		fmt.Println("Today.")
	case today + 1:
		fmt.Println("Tomorrow.")
	case today + 2:
		fmt.Println("In two days.")
	case today + 3, today + 4, today + 5:
		fmt.Println("In 3, 4 or 5 days.")
	default:
		fmt.Println("Too far away.")
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant