Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Switch Statement | Control Structures
course content

Course Content

Introduction to GoLang

Switch StatementSwitch Statement

The switch statement provides a convenient way to compare an expression against multiple values. Below is the basic syntax of the switch statement:

Here are some important points regarding the switch statement:

  • The expression is evaluated once, and its value is compared against the values specified in each case;
  • The block of code under the matching case is executed, and the remaining cases are ignored;
  • If no case matches, the code block under default is executed. The default case is optional and can be left out.

Here is an example of how switch can be used in a program:

go

index.go

Note

You can omit braces for the case code blocks.

How is a switch statement initiated in Go?

Select the correct answer

Everything was clear?

Section 3. Chapter 5
course content

Course Content

Introduction to GoLang

Switch StatementSwitch Statement

The switch statement provides a convenient way to compare an expression against multiple values. Below is the basic syntax of the switch statement:

Here are some important points regarding the switch statement:

  • The expression is evaluated once, and its value is compared against the values specified in each case;
  • The block of code under the matching case is executed, and the remaining cases are ignored;
  • If no case matches, the code block under default is executed. The default case is optional and can be left out.

Here is an example of how switch can be used in a program:

go

index.go

Note

You can omit braces for the case code blocks.

How is a switch statement initiated in Go?

Select the correct answer

Everything was clear?

Section 3. Chapter 5
some-alt