Boolean or Bool

Description

  • true or false

  • Represented also as 1 (true) or 0 (false)

  • Whether it’s capitalized depends on the language

  • Great for control and sensors

Examples:

Processing:

boolean lightOn = false;

C#

bool lightOn = false;

JavaScript

var gameOver = true;

Python:

gameOver = False

Shortcut

Using an exclamation mark ( ! ) at the beginning of a boolean variable name is short for “the opposite” of the variable

This does not update the variable.

Examples:

Processing and Java-based example:

boolean lightOn = false;

println(lightOn); // Prints “false” to console
println(!lightOn); // Prints “true” to console

C# example:

bool lightOn = false;

print(lightOn); // Prints “false” to console
print(!lightOn); // Prints “true” to console

This "shortcut" might not exist in Python.

Last updated