Switch Cases in Go

May 7, 2021

Course Instructor: Elliot Forbes

Hey Gophers! My name is Elliot and I'm the creator of TutorialEdge and I've been working with Go systems for roughly 5 years now. Feel free to reach out to me on twitter - @Elliot_F


package main

import "runtime"

func main() {
	println("Switch Statements in Go")
	var customerHeight int = 140
	customerAge := 18

	switch {
	case customerHeight >= 150 || customerAge >= 18:
		println("can access ride")
	case customerHeight >= 120:
		println("can access children's rides")
		println("cannot access rides")

	switch os := runtime.GOOS; os {
	case "darwin":
		println("os x")
	case "linux":
		println("linux machine")
		println("something else")



$ go run main.go
Switch Statements in Go
can access ride
os x