-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloops.go
52 lines (40 loc) · 976 Bytes
/
loops.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
package main
import (
"fmt"
)
// nao se usa range em struct
func main() {
i := 0
for i < 10 {
i++
fmt.Println("Incrementando i:", i)
//time.Sleep(time.Second)
}
fmt.Println("----------------")
for j := 0; j < 10; j++ {
fmt.Println("Incrementando j:", j)
//time.Sleep(time.Second)
}
fmt.Println("----------------")
nomes := [3]string{"Joao", "Davi", "Lucas"} // array
nomes2 := []string{"Joao", "Davi", "Lucas"} // slice
for indice, nome := range nomes {
fmt.Println("indice:", indice, "nome:", nome)
}
fmt.Println("----------------")
for _, nome := range nomes2 {
fmt.Println("nome:", nome)
}
fmt.Println("----------------")
for indice, letra := range "PALAVRA" {
fmt.Println(indice, " - código ASCII:", letra, " - valor:", string(letra))
}
fmt.Println("----------------")
usuario := map[string]string{
"nome": "Leonardo",
"sobrenome": "Silva",
}
for chave, valor := range usuario {
fmt.Println(chave, valor)
}
}