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

View File

@@ -0,0 +1,27 @@
package main
import "fmt"
func main() {
// basic
if 7%2 == 0 {
fmt.Println("7 is even")
} else {
fmt.Println("7 is odd")
}
// if statement without an else
if 8%4 == 0 {
fmt.Println("8 is divisible by 4")
}
// statements can precede conditionals; any variables declared in this statement are available in all branches
if num := 9; num < 0 {
fmt.Println(num, "is negative")
} else if num < 10 {
fmt.Println(num, "has 1 digit")
} else {
fmt.Println(num, "has multiple digits")
}
}