Introduction To Ruby
Until

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

Example

# until

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

gets

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.

Challenge

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