Introduction To Ruby

The until statement is the reverse of the while. It executes the block of code until a condition is met.


# until

x = 0
until x==10 do
   x = x + 1
   puts x


You can convert between while and until by simply negating the main condition. Rather like the unless statement, the main reason you would use an until is because it makes the code make more sense when read. Most of the time, you are likely to use the while.


  1. Pick any one of the programs that you wrote with while loops. Refactor it so that it uses an until.