starting go by example

This commit is contained in:
2021-12-31 15:36:34 +01:00
parent bafba8a7b6
commit afe165089d
11 changed files with 340 additions and 0 deletions

34
5-go-by-example/5-for.go Normal file
View File

@@ -0,0 +1,34 @@
package main
import "fmt"
// for is Gos only looping construct
func main() {
// basic type with a single condition
i := 1
for i <= 3 {
fmt.Println(i)
i = i + 1
}
// classic initial/condition/after
for j := 7; j <= 9; j++ {
fmt.Println(j)
}
// without a condition will loop repeatedly until break or return
for {
fmt.Println("loop")
break
}
// continue to the next iteration
for n := 0; n <= 5; n++ {
if n%2 == 0 {
continue
}
fmt.Println(n)
}
}