Booleans
True or False
In computer programming, booleans are special data types. They were the first data types ever created, and all other types are derived from them.
If you have ever heard that computers only understand 0's and 1's, then you know what booleans are. Without booleans, there would be no programs.
The two boolean values are TRUE and FALSE (also called "on" state and "off" state, or "1" state and "0" state) and Sonar has first-class support for booleans through the true
and false
keywords:
How Booleans are made
In Sonar, there are two ways booleans can be created:
By using a logical operator (e.g > or <)
By initialising a variable
In this section, we will explore how logical operators generate booleans. Another section on variables will more fully discuss how variables work in Sonar.
Consider these statements:
"The highest mountain in the world is the Mt. Everest"
"The sun rises in the east and sets in the west"
"2 + 2 equals 4"
Each of these statements are true statements and would produce boolean values of TRUE in Sonar code.
Last updated