O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition by Zed A. Shaw

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required