-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
45 lines (39 loc) · 802 Bytes
/
main.go
File metadata and controls
45 lines (39 loc) · 802 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
// `for` is the only kind of loop in So.
// Here are some examples of how to use it.
package main
func main() {
// The most basic kind, with a single condition.
i := 1
for i <= 3 {
println(i)
i = i + 1
}
// A classic initial/condition/after `for` loop.
for j := 7; j <= 9; j++ {
println(j)
}
// Loop from 0 to n-1 (range over integers).
const n = 10
for i := range n {
print(i)
}
println()
// Range also works without a loop variable, if you don't need it.
for range n {
print(".")
}
println()
// Infinite loop runs until a `break`` statement exits the loop
// or a `return` statement exits the function.
for {
println("loop")
break
}
// `continue` jumps to the next iteration of the loop.
for n := range 6 {
if n%2 == 0 {
continue
}
println(n)
}
}