go-learning/1flow/if.go

25 lines
380 B
Go
Raw Permalink Normal View History

2023-07-09 22:03:02 +03:00
package main
import (
"fmt"
)
func main() {
fmt.Println("No parantheses, braces required")
val := 1
if val == 0 {
fmt.Println("1")
} else if val == 1 {
fmt.Println("2")
} else {
fmt.Println("3")
}
fmt.Println("Also you can execute short statement before condition")
if val2 := 1; val2 > 0 {
fmt.Println(val2)
}
// fmt.Println(val2) // ERROR, out of scope
}