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 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

@davecheney davecheney commented May 27, 2020

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.

@davecheney davecheney closed this May 27, 2020
@eliashanna78
Copy link
Author

@eliashanna78 eliashanna78 commented May 27, 2020

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

@davecheney
Copy link
Contributor

@davecheney davecheney commented May 27, 2020

You're welcome, and welcome to Go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.