Exercise 28. Boolean Practice

The logic combinations you learned from the last exercise are called “Boolean” logic expressions. Boolean logic is used everywhere in programming. It is an essential, fundamental part of computation and knowing them very well is akin to knowing your scales in music.

In this exercise you will take the logic exercises you memorized and start trying them out in Ruby. Take each of these logic problems and write what you think the answer will be. In each case it will be either true or false. Once you have the answers written down, you will start Ruby on your Terminal and type each logic problem in to confirm your answers.

1. true && true

2. false && true

3. 1 == 1 && 2 == 1

4. "test" == "test"

5. 1 == 1 || 2 != 1

6.

Get Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.