-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path17_switch_combinations.go
More file actions
39 lines (36 loc) · 959 Bytes
/
17_switch_combinations.go
File metadata and controls
39 lines (36 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Pátá část
// Konstrukce pro řízení běhu programu v jazyce Go
// https://www.root.cz/clanky/konstrukce-pro-rizeni-behu-programu-v-jazyce-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z páté části:
// https://github.com/tisnik/go-root/blob/master/article_05/README.md
//
// Demonstrační příklad číslo 17:
// Řídicí konstrukce switch: kombinace podmínek a fallthrough.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_05/17_switch_combinations.html
package main
func classify(x int) string {
switch {
case x == 0:
return "nula"
case x%2 == 1:
return "liché číslo"
case x%2 == 0:
fallthrough
default:
return "sudé číslo"
}
}
func main() {
for x := 0; x <= 10; x++ {
println(x, classify(x))
}
}