Ruby Until Loop

The Ruby until loop runs until the given condition evaluates to true. It exits the loop when condition becomes true. It is just opposite of the while loop which runs until the given condition evaluates to false.

The until loop allows you to write code which is more readable and logical.

Syntax:


  1. until conditional  
  2.    code  
  3. end  

Example:


  1. i = 1   
  2. until i == 10   
  3.     print i*10, "\n"   
  4.     i += 1   
  5. end  

Output:

Ruby until loop 1

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *