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 36. Designing and Debugging

Image

Now that you know if-statements, I’m going to give you some rules for for-loops and while-loops that will keep you out of trouble. I’m also going to give you some tips on debugging so that you can figure out problems with your program. Finally, you will design a little game similar to the last exercise, but with a slight twist.

Rules for If-Statements

1. Every if-statement must have an else.

2. If this else should never run because it doesn’t make sense, then you must use a die function in the else that prints out an error message and dies, just like we did in the last exercise. This will find many errors. ...

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