Art Swan <artswan / ktc.com> writes:

> Using for x in (1..20) format for fixed repeating of a task is
> easy enough, but how do you modify the syntax to count down from
> say, a large number to 0? Also, how do you have it loop forever?

The ability to iterate is built in to integers, so you can also say:


   10.times { |x|
     # ...
   }

   5.upto(23) { |x|
      # ...
   }

   12.downto(3) { |x|
      # ...
   }

To loop endlessly, start this sentence again. Alternatively, use

   loop {
     # ...
   }


Regards


Dave