Learning GO
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
module main.go
|
||||
|
||||
go 1.23.1
|
||||
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
)
|
||||
|
||||
func condition() {
|
||||
for i := 0; i < 10; i++ {
|
||||
if i%2 == 0 {
|
||||
fmt.Println("this number is even: ", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sqrt(x float64) float64 {
|
||||
z := 1.0
|
||||
for i := 0; i < 10; i++ {
|
||||
z -= (z*z - x) / (z * 2)
|
||||
fmt.Println(z)
|
||||
}
|
||||
return z
|
||||
}
|
||||
|
||||
func main() {
|
||||
defer condition()
|
||||
fmt.Println(sqrt(2))
|
||||
|
||||
fmt.Print("Go runs on ")
|
||||
switch os := runtime.GOOS; os {
|
||||
case "Windows":
|
||||
fmt.Println("MacOs.")
|
||||
case "Linx":
|
||||
fmt.Println("Linux.")
|
||||
default:
|
||||
fmt.Printf("%s.\n", os)
|
||||
}
|
||||
|
||||
fmt.Println("*******************")
|
||||
fmt.Println("When's Saturday?")
|
||||
today := time.Now().Weekday()
|
||||
switch time.Saturday {
|
||||
case today + 0:
|
||||
fmt.Println("Today.")
|
||||
case today + 1:
|
||||
fmt.Println("Tomorrow.")
|
||||
case today + 2:
|
||||
fmt.Println("In two days.")
|
||||
default:
|
||||
fmt.Println("Too far away.")
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user