-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_flows.go
93 lines (66 loc) · 1.44 KB
/
3_flows.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import "fmt"
func main() {
// FLOW CONTROL
// matrix = true
// if matrix
// puts "Took the red pill"
// else
// puts "Blue pill it is. Boo!"
// end
fmt.Println("-----")
matrix := true
if matrix {
fmt.Println("Took the red pill")
} else {
fmt.Println("Blue pill it is. Boo!")
}
// ITERADORES
// all your FOR are belong to us
// FOR normal
// 5.times.do |n|
// puts "A la cuenta de... #{ n }"
// end
fmt.Println("-----")
for i := 0; i < 5; i++ {
fmt.Printf("A la cuenta de... %d\n", i)
}
// WHILE
// mola = true
// j = 0
// while mola do
// puts "Mola!"
// j += 1
// mola = false if j > 2
// end
fmt.Println("-----")
mola := true
j := 0
for mola {
fmt.Println("Mola!")
if j++; j > 2 {
mola = false
}
}
// EACH (_with_index)
// puts "MISSING:"
// found_people = ["Hurley", "Jack", "Kate", "Ben", "Sayid"]
// found_people.each_with_index do |peep, index|
// puts "#{ index } #{ peep }"
// end
fmt.Println("-----")
fmt.Println("MISSING:")
foundPeople := []string{ "Hurley", "Jack", "Kate", "Ben", "Sayid" }
for index, peep := range foundPeople {
fmt.Println((index + 1), peep)
}
// SWITCH
fmt.Println("-----")
const answerToLife = 1
switch answerToLife {
case 1,2,3,4,5:
fmt.Println("Nope.")
case 42:
fmt.Println("La respuesta a la vida es 42. ¿Cuál es la pregunta?")
}
}