go switch case

switch time {
	case "morning":
		fmt.Println("Time to wake up!")
	case "night":
  		fmt.Println("Time to go to bed.")
	default:
  		fmt.Println("Enjoy life")
}

3.5
10
Awgiedawgie 440215 points

                                    package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Print("Go runs on ")
	switch os := runtime.GOOS; os {
	case "darwin":
		fmt.Println("OS X.")
	case "linux":
		fmt.Println("Linux.")
	default:
		// freebsd, openbsd,
		// plan9, windows...
		fmt.Printf("%s.\n", os)
	}
}

3.5 (10 Votes)
0
4.25
8
Awgiedawgie 440215 points

                                        // switch statement
    switch operatingSystem {
    case "darwin":
        fmt.Println("Mac OS Hipster")
        // cases break automatically, no fallthrough by default
    case "linux":
        fmt.Println("Linux Geek")
    default:
        // Windows, BSD, ...
        fmt.Println("Other")
    }

    // as with for and if, you can have an assignment statement before the switch value
    switch os := runtime.GOOS; os {
    case "darwin": ...
    }

    // you can also make comparisons in switch cases
    number := 42
    switch {
        case number < 42:
            fmt.Println("Smaller")
        case number == 42:
            fmt.Println("Equal")
        case number > 42:
            fmt.Println("Greater")
    }

    // cases can be presented in comma-separated lists
    var char byte = '?'
    switch char {
        case ' ', '?', '&', '=', '#', '+', '%':
            fmt.Println("Should escape")
    }

4.25 (8 Votes)
0
4.4
5
Phoenix Logan 186120 points

                                        switch time.Now().Weekday() {
    case time.Saturday, time.Sunday:
        fmt.Println("It's the weekend")
    default:
        fmt.Println("It's a weekday")
    }

4.4 (5 Votes)
0
Are there any code examples left?
New code examples in category Go
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
golamng switch case case switch golang switch statement in golang where use switch and if golang golang switch case type case go default case in switch golang switch else case golang or in switch case golang syntax on switch case in go swich case golang golang switch syntax golang switch case example go case switch go switch case fallthrough switch go to case golang switch example switch case fallthrough golang golang switch case with or go case statement nintendo switch go letgo go switch with := using or in switch case golang case statement golang switch case go lang case statement go go language use cases switch case break nintendo switch go go switch case type golang case switch golang switch cas case statement in golang golang type switch case go swithc case golang switch function s go case golang switch case or switch statement golang does go have switch statement go switch statements go example switch golang switch break golang type switch golang switch writer default for golang swiotch if switch go lang golang switch case statement switch statement go cs go case simulator go cases go switch string how to go to another case in switch in golang c lang swith case switch case in golang fallthrough go switch switch continue golang switch go case in golang golang case statement break golang case statement switch in go break in golang switch golang switch case string switch golang example switch case in go lang golang if or on switch case golang if on switch case switch & case golang switch statement in go go switch case case example golang which case does go use case golang golang case go switch case one of what is a switch statement in go how to end a switch statement in go case in go lang go case syntax swtich case golang golang swtich case switch statements golang switch case golang golang switch statements switch case go switch statements in go golang switch case golang switch statement go switch go switch statement
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source