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

two switch cases to the same logic doesn't work #39267

Closed
eliashanna78 opened this issue May 27, 2020 · 3 comments
Closed

two switch cases to the same logic doesn't work #39267

eliashanna78 opened this issue May 27, 2020 · 3 comments

Comments

@eliashanna78
Copy link

eliashanna78 commented May 27, 2020

Hi,
I develop Go using goland, I noticed that using:

switch x:
case y:
case z:
logic1

default:
logic2

If I enter the switch with value y, I will jump to default behaviour (logic2) and not what I expected which is logic1, would be nice if I could use this syntax.

Thanks,
Elias

@davecheney
Copy link
Contributor

The syntax you want is

switch x {
case x, y:
   logic1
default:
  logic2
}

Unlike many projects on GitHub, the Go project does not use its bug tracker for general discussion or asking questions. We only use our bug tracker for tracking bugs and tracking proposals going through the Proposal Process.

Please see https://golang.org/wiki/Questions for good places to ask questions.

@eliashanna78
Copy link
Author

Hi,
Sorry for the misuse.
And thanks for the explanation.
Elias

@davecheney
Copy link
Contributor

You're welcome, and welcome to Go!

@golang golang locked and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants