Lesson 5 of 60
GoControl Flow: if, switch, for Loops
20 minutes
Course progress8%
Control Flow: if, switch, for Loops
Control flow lets your program make decisions and repeat actions. Go keeps these constructs readable and consistent.
if statement
Use if to run code conditionally.
if n%2 == 0 {
fmt.Println("even")
} else {
fmt.Println("odd")
}