Theory
if, boolean logic and switch
So far the program executed steps in order. Today it learns to choose.
if / else. The condition is any bool value:
if it.Pages > 300 {
fmt.Println("A thick book")
} else if it.Pages > 100 {
fmt.Println("Medium")
} else {
fmt.Println("Thin")
}
Boolean operators combine conditions: && (and), || (or), ! (not):
if it.Read && it.Pages > 300 { ... } // read AND thick
if it.Pages < 50 || !it.Read { ... } // thin OR not read
switch. When you compare one value against many options, an if chain becomes a staircase — switch is cleaner:
switch choice {
case "1":
printItem(it)
case "2":
fmt.Println("Marked.")
default:
fmt.Println("Unknown choice.")
}
Go's switch stops by itself after each case — no break needed (unlike C). default is the "nothing matched" branch: exactly the one that will catch bad input.