O'Reilly logo

Ruby Quick Syntax Reference by Matt Clements

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

CHAPTER 9

image

Loops and Iterators

Previously, we have discussed various data types within Ruby, how these operate, and the methods that we have available. We have also looked at some examples as to using them within an application. We are now going to investigate loops and iterators within Ruby. There are many types of loops/iterators within Ruby, from simple to complex methods.

Loop Method

The simplest type of iterator within Ruby is a loop method. While the name sounds like this is a loop, this is in fact an iterator method. First, we will set up the simplest type of loop, the infinite loop, printing out Hello World on a new line forever.

#!/usr/bin/env ...

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