-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.go
44 lines (40 loc) · 873 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
package main
import "fmt"
func main() {
fmt.Println("\n\nLoop\n")
// **********************************************************************
// For loop: while, do-while as well
// **********************************************************************
for i:=0; i<10; i++ {
if i == 7 {
fmt.Println("break")
break
}
fmt.Println(i)
}
fmt.Println("\n")
for i:=0; i<10; i++ {
if i == 7 {
fmt.Println("continue")
continue
}
fmt.Println(i)
}
fmt.Println("\n\nwhile\n")
// while from for loop
j := 10
for j<20 {
fmt.Println(j)
j++
}
fmt.Println("\n\nDo While\n")
// Do-while from for loop
k :=21
for {
fmt.Println(k)
k++
if k > 30 {
break
}
}
}