Difference between revisions of "Ruby While and Until Loops"
(New page: If computers do one thing well it is performing tasks very quickly. One thing computers do even better is performing the same task over and over again until specific criteria are met (or e...) |
(No difference)
|
Revision as of 15:49, 26 November 2007
If computers do one thing well it is performing tasks very quickly. One thing computers do even better is performing the same task over and over again until specific criteria are met (or even infinitely if that is what is required). One this that computers are very bad at, however, is doing anything without being told to do it. Given these facts, it should come as no surprise that just about every programming language, Ruby included, provide mechanisms for instructing a computer system to repeat tasks.
In this chapter of Ruby Essentials we will look the structures provided by Ruby to allow loops to be built into applications.
The Ruby While Loop
The Ruby while loop is designed to repeat a task until a particular expression is evaluated to be true. The syntax of a while loop is as follows:
while expression do
... ruby code here ...
end