Boolean Expressions
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
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:
3 > 0 produces the value true, because 3 is greater than 0.20 == 10 produces the value false, because 20 is not equal to 10.10 == 10 produces the value true, because 10 is equal to 10.We can create boolean expressions with any value type. For example, strings or vectors:
"hello" == "Hello" produces the value false because one of the two strings starts with a capital letter and the other does not."Godot" == "Godot" produces the value true because both strings are exactly the same.Vector2(1,1) == Vector2(1,1) produces the value true because both vectors are the same.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.
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.
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.
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.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…