• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

Switch in Go

May 4, 2022 Go

In this post, you will learn how to work with switch so that you can use that same knowledge and thus evolve.

  • the switch is another way of working with decisions and it can only check an equality relationship, that is, it cannot use comparison operators (and of course, note that there are two types of switch (by expression and/or by type) );
  • the case compares what was defined in itself with the content of the argument that was defined in the switch;
  • default is executed when the content of the argument that was defined in the switch is not found in any case.
package main

import "fmt"

func main() {
	_case := "D"

	switch (_case) {
		case "A":
			fmt.Println("The case A exists.")
		case "B":
			fmt.Println("The case B exists.")
		case "C":
			fmt.Println("The case C exists.")
		default:
			fmt.Printf("The case %s does not exist.", _case)
	}
}

// The case D does not exist.

Don’t forget to watch the video and you can always read this post in Portuguese.

Happy coding!

Previous Next

Categories

  • Announcements
  • Python
  • C#
  • Java
  • Go

Latest Posts

  • for Loop in Go
    May 5, 2022
  • Switch in Go
    May 4, 2022
  • Comparison Operators in Go
    May 3, 2022
+351913416022
contact@nelsonsilvadev.com
Porto, Portugal
Nelson Silva © 2022 All Rights Reserved