Tsallaka zuwa abun ciki
Justice Tech School

Booleans and Logic

bool holds true or false. Combine with && || and !. Go has no truthy values, conditions must be booleans.

Example
package main

import "fmt"

func main() {
	a, b := true, false
	fmt.Println(a && b, a || b, !a)
	n := 5
	fmt.Println(n > 3 && n < 10)
}

Result

false true false
true

Exercise

Logical not.

a

Quiz Test

Can an int be used as a condition?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.