December 2014
Intermediate to advanced
164 pages
2h 14m
English
CHAPTER 9
![]()
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 ...Read now
Unlock full access