Go: Decisions


Example: If statement with string in Go


	package main
	import "fmt"
	func main() {

		var day = "Saturday"
		if day == "Saturday" {
			fmt.Println("It's the weekend.")
		}
	}

	

Output:

  It's the weekend.


Example: If statement with integers in Go


	package main
	import "fmt"
	func main() {

		var score int = 98

		if score >= 200 {
			fmt.Println("Amazing bowling score")
		} else if score >= 150 {
			fmt.Println("Excellent bowling score")
		} else if score >= 100 {
			fmt.Println("Good bowling score")
		} else {
			fmt.Println("Hope you enjoyed yourself")
		}

	}
	

Output:

  Hope you enjoyed yourself


Example: If statements in Go


	package main
	import "fmt"
	func main() {

		if 100 % 10 == 0 {
			fmt.Println("100 is divisible by 0.")
		} else {
			fmt.Println("100 is not divisible by 0")
		}

		if 15 % 3 == 0 {
			fmt.Println("15 is divisible by 3")
		}

		if x := 199; x < 0 {
			fmt.Println(x, "is negative")
		} else if x < 10 {
			fmt.Println(x, "has 1 digit")
		} else {
			fmt.Println(x, "has more than 1 digit")
		}
	}

	

Output:

  100 is divisible by 0.
  15 is divisible by 3
  199 has more than 1 digit