-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path18_switch_on_string.go
48 lines (45 loc) · 1.12 KB
/
18_switch_on_string.go
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
40
41
42
43
44
45
46
47
48
// 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 18:
// Řídicí konstrukce switch s vyhodnocovaným výrazem typu string.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_05/18_switch_on_string.html
package main
func command(x string) string {
switch x {
case "":
return "missing command"
case "help":
fallthrough
case "info":
return "help"
case "bye":
fallthrough
case "exit":
fallthrough
case "quit":
return "quit"
default:
return "unknown command"
}
return "unknown command"
}
func main() {
println(command(""))
println(command("bzz bzz bzz"))
println(command("bye"))
println(command("quit"))
println(command("exit"))
}