O'Reilly logo

Learn Ruby the Hard Way: A Simple and Idiomatic Introduction to the Imaginative World of Computational Thinking with Code, Third Edition, Video Enhanced 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 29. What If

Image

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 see if your practice has paid off.

ex29.rb

 1    people = 20  2    cats = 30  3    dogs = 15  4  5  6    if people < cats  7      puts "Too many cats! The world is doomed!"  8    end  9 10    if people > cats 11      puts "Not many cats! The world is saved!" 12    end 13 14    if people < dogs 15      puts "The world is drooled on!" 16    end 17 18    if people > dogs 19      puts "The world is dry!" 20    end 21 22 23    dogs += 5 24 25    if people ...

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