[Go] Use a switch statement

Created on November 30, 2026

Use switch to select a branch based on a value. The following example compares str with the case values and prints the result for the matching case.

package main

import (
    "fmt"
)

func main() {
    str := "a"

    switch(str){
    case "a":
        fmt.Println("a")
    case "b":
        fmt.Println("b")
    }
}
Go