July 2011
Intermediate to advanced
400 pages
8h 46m
English
Ruby has a few other loop constructs too. This is how to do a while loop:
while tired sleep end
Or, here’s another way to put it:
sleep while tired
Even though the syntax of these two examples is different, they perform the same function. In the first example, the code between while and end (here a call to a method named sleep) executes just as long as the Boolean condition (which, in this case, is the value returned by a method called tired) evaluates to true. As in for loops, the keyword do may optionally be placed between the test condition and the code to be executed when these appear on separate lines; the do keyword is obligatory when the test condition and the code to be executed appear on the same line.
In the second ...
Read now
Unlock full access