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
Exercise 33. While Loops
Now to totally blow your mind with a new loop, the while-loop. A while-loop will keep executing the code block under it as long as a Boolean expression is true.
Wait, you have been keeping up with the terminology, right? You should know that Ruby has three kinds of code blocks you need to read. You have the kind that if-statements use, where code is started after the if, and the block of code is ended with end. You then have two kinds for .each style blocks. Either you use do ... end or { ... } when making a block of code. When I use the characters ... in that last description I do not mean type ... I mean them in the normal English way of “and then some stuff here”. If you don’t quite understand this go back and redo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access