concept boolean value in category go

appears as: Boolean value, Boole values, Boole values
Get Programming with Go

This is an excerpt from Manning's book Get Programming with Go.

Listing 3.1. A function that returns a Boolean value: contains.go
package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println("You find yourself in a dimly lit cavern.")

    var command = "walk outside"
    var exit = strings.Contains(command, "outside")

    fmt.Println("You leave the cave:", exit)            #1
 }

True and false are Boolean values, so named after 19th century mathematician George Boole. Several functions in the standard library return a Boolean value. For example, the following listing uses the Contains function from the strings package to ask if the command variable contains the text “outside”. It does contain that text, so the result is true.

Listing 3.1. A function that returns a Boolean value: contains.go
package main

import (
    "fmt"
    "strings"
)

func main() {
    fmt.Println("You find yourself in a dimly lit cavern.")

    var command = "walk outside"
    var exit = strings.Contains(command, "outside")

    fmt.Println("You leave the cave:", exit)            #1
 }

10.5. Converting Boolean values

The Print family of functions displays the Boolean values true and false as text. As such, the next listing uses the Sprintf function to convert the Boolean variable launch to text. If you want to convert to numeric values or different text, a humble if statement works best.