55 lines
832 B
Go
55 lines
832 B
Go
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.")
|
|
}
|
|
|
|
}
|