-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor.go
More file actions
47 lines (39 loc) · 753 Bytes
/
for.go
File metadata and controls
47 lines (39 loc) · 753 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
40
41
42
43
44
45
46
47
package main
func main() {
counter := 1
for counter <= 10 {
println("Perulangan ke", counter)
counter++
}
// for with statement
for i := 0; i < 10; i++ {
println("Perulangan ke", i)
}
// for with break
for i := 0; i < 10; i++ {
if i == 5 {
break
}
println("Perulangan ke", i)
}
// for with continue
for i := 0; i < 10; i++ {
if i%2 == 0 {
continue
}
println("Perulangan ke", i)
}
// for with range
names := []string{"Wiku", "Karno", "Naruto"}
for i, name := range names {
println("Perulangan ke", i, "dengan nama", name)
}
// for with range and ignore index
for _, name := range names {
println("Nama", name)
}
// for with range and ignore value
for i := range names {
println("Index", i)
}
}