• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

if, else if and else in Go

May 2, 2022 Go

In this post, you will learn how to work with decisions (if, else if and else) so that you can use that same knowledge and thus evolve.

package main

import "fmt"

/*
  (if - if) condition is true {
    the code inside the if is executed
  }
  (else if - otherwise if) condition is true (else if only occurs if if condition is false) {
    code inside else if is executed
  }
  (else - if not) no condition (only occurs if condition of if and else if are false) {
    the code inside the else is executed
  }
*/

func main() {
	x := 30

	if x == 10 {
		fmt.Println("The value of x is equal to 10.")
	} else if x == 20 {
		fmt.Println("The value of x is equal to 20.")
	} else {
		fmt.Println("The value of x is different from 10 and 20.")
	}
}

// The value of x is different from 10 and 20.

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