Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

5.2. Loops

This section documents Ruby’s simple looping statements: while, until, and for. Ruby also includes the ability to define custom looping constructs known as iterators. Iterators (see Section 5.3) are probably more commonly used than Ruby’s built-in looping statements; they are documented later in this chapter.

5.2.1. while and until

Ruby’s basic looping statements are while and until. They execute a chunk of code while a certain condition is true, or until the condition becomes true. For example:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial