Mega Code Archive

 
Categories / Ruby / Statement
 

As unless is a negated form of if, until is really a negated form of while

# Compare the following statements. The first is a while loop: weight = 150 while weight < 200 do   puts "Weight: " + weight.to_s   weight += 5 end # Here is the same logic expressed with until: weight = 150 until weight == 200 do   puts "Weight: " + weight.to_s   weight += 5 end