Boolean Data Type
Part of the Fundamentals section of Coddy's Ruby journey — lesson 6 of 88.
The boolean data type can only hold two possible values: true and false. These values represent the concepts of true and false, which are fundamental for controlling program flow and making comparisons. Notice that both values are written in lowercase without quotes.
Creating a boolean variable follows the same pattern you've learned:
is_complete = true
has_error = falseBoolean values become incredibly useful when your program needs to make decisions, check conditions, or store the results of comparisons. They form the foundation for controlling what your code does in different situations.
Challenge
EasyCreate three boolean variables to represent different system states. First, create a variable called is_online and assign it the value true. Then create a variable called has_permission and assign it the value false. Finally, create a variable called system_ready and assign it the value true. Display all three variables using the puts command.
Cheat sheet
The boolean data type holds two possible values: true and false. Both values are written in lowercase without quotes.
Creating boolean variables:
is_complete = true
has_error = falseBoolean values are used for making decisions, checking conditions, and storing comparison results.
Try it yourself
# TODO: Write your code here
# Create the three boolean variables and display them using putsThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 42Variables and Data Types
Numbers and VariablesString Data TypeBoolean Data TypeSymbol Data TypeChecking Data TypesNaming ConventionsRecap - Variable Creation8Loops
For Loop with RangesWhile LoopBreakNextRecap - FactorialTimes LoopUntil LoopNested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators6Basic IO
Output with putsOutput with print and pOutput With VariablesInput with getsChomp MethodType ConversionRecap - Age CalculatorRecap - True or False