Boolean Expressions

2025/12/27

Type
Learning Resource
Format
Glossary Article
Version
General
Subject Tags
Code
Assets
All else
Copyright 2016-2026, GDQuest
Created
2026/02/16
Updated
2025/12/27

Boolean Expressions

A boolean expression is any expression that produces one of two particular values called boolean values: true or false.

A boolean expression can result from a comparison or a function call. For example, the comparison 10 < 5 ("Is 10 smaller than 5?") is a boolean expression. When the computer reads this, it runs the comparison and produces the value false because 10 is not smaller than 5.

Here are more examples of comparisons with numbers:

We can create boolean expressions with any value type. For example, strings or vectors:

All these examples use values directly (numbers, strings, vectors...), but you can use variables instead, as variables are a way to store and reference values:

var health = 3
if health == 0:
    die()

Because the health variable has a value of 3 in this example, the boolean expression health == 0 ("is health equal to 0?") is equivalent to writing 3 == 0. Since the value of a variable can change during program execution, variables allow us to make dynamic comparisons.

Single and double equal signs are not the same operator

Be careful! The code 3 = 12 is not a boolean expression. It will produce an error.

In programming, a single equal sign (=) is the assignment operator. This line of code means "Put the value 12 in 3", which is not valid for the computer.

It is different from the is equal to operator, which uses two equal signs (==) to compare if two numbers are equal.

Also, var my_name = "Alice" is not an expression either. While the code is valid, this line does not produce a value. It assigns the value "Alice" to the variable named my_name.

Be careful: Decimal numbers are imprecise

What do you think the expression 0.3 * 3 == 0.9 will produce?

In almost all programming languages, it will be false!

Decimal numbers ("floats" in programming jargon, short for floating-point numbers) are generally imprecise in the computer's memory.

Because of that, you cannot always reliably compare if two floats are equal. Note that you can safely make comparisons like "larger than" or "smaller than". It's some equality comparisons that can cause problems.

Most languages provide functions to test if two decimal numbers are approximately equal, and Godot is no exception: it has a function named is_equal_approx() for that: is_equal_approx(0.3 * 3, 0.9) will return true.

Become an Indie Gamedev with GDQuest!

Don't stop here. Step-by-step tutorials are fun but they only take you so far.

Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.

Nathan

Founder and teacher at GDQuest
  • Starter Kit
  • Learn Gamedev from Zero
Check out GDSchool

You're welcome in our little community

Get help from peers and pros on GDQuest's Discord server!

20,000 membersJoin Server

Contribute to GDQuest's Free Library

There are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!