Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

38 lines (28 sloc) 1.002 kb

Exercise 29: What If

Here is the next script of Ruby you will enter, which introduces you to the if-statement. Type this in, make it run exactly right, and then we'll try see if your practice has paid off.

What You Should See

$ ruby ex29.rb
Too many cats! The world is doomed!
The world is dry!
People are greater than or equal to dogs.
People are less than or equal to dogs.
People are dogs.

Extra Credit

In this extra credit, try to guess what you think the if-statement is and what it does. Try to answer these questions in your own words before moving onto the next exercise:

  1. What do you think the if does to the code under it?
  2. Can you put other boolean expressions from Ex. 27 in the if-statement? Try it.
  3. What happens if you change the initial variables for people, cats, and dogs?
Jump to Line
Something went wrong with that request. Please try again.