Syntax

Go Switch Syntax

In Go, switch: branches on a value (no break needed) — switch n { case 1: ... default: ... }

Quick Answer

Syntax
switch n { case 1: ... default: ... }
GoSyntax

Switch

Code example
switch n { case 1: ... default: ... }

Branches on a value (no break needed).

Learn More

How to switch in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Switch Syntax

Use switch n { case 1: ... default: ... }.

Related Syntax References

Frequently asked questions

What is the Go syntax for switch?

Use this pattern: switch n { case 1: ... default: ... }

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify