learning about golang for loop

This commit is contained in:
Fabio Montefuscolo 2024-03-11 17:30:29 +01:00
parent 51d9fa4fc3
commit 7af8fab3df
Signed by: fabiomontefuscolo
GPG key ID: B98DA1C6A4DE48B5

28
src/05-for.go Normal file
View 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)
}
}