-
Book Overview & Buying
-
Table Of Contents
The Ruby Workshop
By :
Loops are a type of program flow that repeat blocks of code. The ability to repeat a block of code allows us to do things such as processing collections of data. Typically, loops will run until a condition is satisfied. For instance, a loop may be run until it has run a certain number of times, or a loop may be run until it has processed all the items in a collection of data. Let's look at the following types of loops in Ruby:
while/do loopsuntil/do loopsdo/while loopsAnother foundational concept for program flow is being able to repeat sections of code until a condition is met. These are called loops and in Ruby there are many ways to create loops. The most basic structure of a loop contains two things:
Here is a simple block using the while keyword:
while true do puts Time.now end...
Change the font size
Change margin width
Change background colour