Code examples from Go Tutorial for Beginners #6 - Control Flow: if/else
basic_if.go- Basic if statementsif_else.go- if-else and else-if chainsshort_statement.go- Short statement syntax (declare variables in if)logical_operators.go- Logical operators (&&, ||, !) and comparison operators
go run basic_if.go
go run if_else.go
go run short_statement.go
go run logical_operators.goif age >= 18 {
fmt.Println("You are an adult")
}if score >= 90 {
fmt.Println("Grade: A")
} else if score >= 80 {
fmt.Println("Grade: B")
} else {
fmt.Println("Grade: F")
}if num := 10; num%2 == 0 {
fmt.Println(num, "is even")
}if hasLicense && hasCar {
fmt.Println("You can drive!")
}Go Tutorial for Beginners #6 - Control Flow: if/else
MIT