Golang true and false Constants with Examples

Golang | true and false Constants: Here, we are going to learn about the true and false constants with examples.
Submitted by IncludeHelp, on October 12, 2021 [Last updated : March 15, 2023]

true and false Constants

In the Go programming language, true and false are the two untyped boolean values, these are boolean constants.

Syntax

true
false

Parameter(s)

  • None

Return Value

None

Example 1

// Golang program to demonstrate the
// example of true and false constants

package main

import (
	"fmt"
)

func main() {
	// Printing the values and types
	// of true and false
	fmt.Printf("%T, %v\n", true, true)
	fmt.Printf("%T, %v\n", false, false)
}

Output

bool, true
bool, false

Example 2

// Golang program to demonstrate the
// example of true and false constants

package main

import (
	"fmt"
)

func main() {
	age := 21
	// Comparison of the expression
	if age >= 18 == true {
		fmt.Println("Eligible for voting")
	} else {
		fmt.Println("Not eligible for voting")
	}
}

Output

Eligible for voting

Golang builtin Package »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.