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 30. Else and If

Image

In the last exercise you worked out some if-statement and then tried to guess what they are and how they work. Before you learn more I’ll explain what everything is by answering the questions you had from Study Drills. You did the Study Drills, right?

1. What do you think the if does to the code under it? An if-statement creates what is called a “branch” in the code. It’s kind of like those choose your own adventure books where you are asked to turn to one page if you make one choice, and another if you go a different direction. The if-statement tells your script, “If this Boolean expression is true, then run the code ...

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