Skip to content

Latest commit

 

History

History
57 lines (43 loc) · 961 Bytes

boolean_zen.md

File metadata and controls

57 lines (43 loc) · 961 Bytes

JumpStart Live (JSL)

Day 4

Boolean Zen

Boolean zen is a phrase used to describe if code using boolean values is written in the most concise way possible. Boolean zen is considered good programming style.

Tips

  • You should never compare to true or false in an if statement, while loop, or until loop

Examples

# not boolean zen
if width > 0 && width < 100
    puts true
else
    puts false
end

# boolean zen
puts width > 0 && width < 100
# not boolean zen
correct = false
until correct == true
    # statement(s)
end

# boolean zen
correct = false
until correct
    # statement(s)
end
# not boolean zen
not_correct = true
while not_correct == true
    # statement(s)
end

# boolean zen
not_correct = true
while not_correct
    # statement(s)
end

Resources