Concept Flow - Boolean values (true, false, nil)
Start
Evaluate expression
Is value true?
Yes No
Use true
Use false
Use nil
End
This flow shows how Ruby evaluates values as true, false, or nil and how each is treated in conditions.
a = true b = false c = nil puts a puts b puts c
| Step | Action | Variable | Value | Output |
|---|---|---|---|---|
| 1 | Assign true to a | a | true | |
| 2 | Assign false to b | b | false | |
| 3 | Assign nil to c | c | nil | |
| 4 | Print a | a | true | true |
| 5 | Print b | b | false | false |
| 6 | Print c | c | nil |
| Variable | Start | After 1 | After 2 | After 3 | Final |
|---|---|---|---|---|---|
| a | undefined | true | true | true | true |
| b | undefined | undefined | false | false | false |
| c | undefined | undefined | undefined | nil | nil |
Boolean values in Ruby: - true and false are Boolean literals. - nil means 'no value' and acts like false in conditions. - Printing true or false shows 'true' or 'false'. - Printing nil shows an empty line. - Use these values in conditions to control flow.
nilnil is used to represent the absence of any value, like an empty box.true and false are Boolean values meaning yes or no, but not "no value". 0 is a number, not a special value for nothing.nil -> Option Anil means no value [OK]true and false for Boolean values.False and FALSE are not valid Ruby keywords. FalseValue is not a keyword but a name.value = nil if value puts "Yes" else puts "No" end
nil in conditionsnil is treated as false in conditions.value is nil, the if value condition is false, so the else branch runs, printing "No".nil acts as false in if [OK]if false puts "No" elsif nil puts "Maybe" else puts "Yes" end
if, elsif, and end, so no syntax error.false is false, nil is also false, so both conditions fail and else runs, printing "Yes".status is either true or nil in Ruby. Which condition correctly does this?status is either true OR nil, so use logical OR (||).status == true || status == nil, which matches the requirement. if status == true && status == nil uses AND, which can never be true for both at once. if status || nil is incorrect syntax and logic. if status != false checks if status is not false, which includes other values too.Pass the test and this pattern moves unknown