Курси /
Introduction to GoLang
Switch 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 eachcase
; - The block of code under the matching
case
is executed, and the remaining cases are ignored; - If no
case
matches, the code block underdefault
is executed. Thedefault
case is optional and can be left out.
Here is an example of how switch
can be used in a program:
index.go
Note
You can omit braces for the
case
code blocks.
Все було зрозуміло?
Секція 3. Розділ 5
Зміст курсу
Introduction to GoLang
Introduction to GoLang
Switch 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 eachcase
; - The block of code under the matching
case
is executed, and the remaining cases are ignored; - If no
case
matches, the code block underdefault
is executed. Thedefault
case is optional and can be left out.
Here is an example of how switch
can be used in a program:
index.go
Note
You can omit braces for the
case
code blocks.
Все було зрозуміло?
Секція 3. Розділ 5