learning about golang for loop
This commit is contained in:
parent
51d9fa4fc3
commit
7af8fab3df
1 changed files with 28 additions and 0 deletions
28
src/05-for.go
Normal file
28
src/05-for.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
i := 1
|
||||||
|
for i <= 3 {
|
||||||
|
fmt.Println("number i =", i)
|
||||||
|
i = i + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for j := 0; j < 3; j++ {
|
||||||
|
fmt.Println("number j =", j)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
fmt.Println("loop with no condition")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
for n := range 6 {
|
||||||
|
if n%2 == 0 {
|
||||||
|
fmt.Println("even number n = ", n)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fmt.Println("odd number n = ", n)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue