Ruby redo Statement

Ruby redo statement is used to repeat the current iteration of the loop. The redo statement is executed without evaluating the loop’s condition.

The redo statement is used inside a loop.

Syntax:

redo  

Example:


  1. i = 0   
  2. while(i < 5)   # Prints "012345" instead of "01234"   
  3.   puts i   
  4.   i += 1   
  5.    redo if i == 5   
  6. end   

Output:

Ruby redo statement 1

Ruby retry Statement

Ruby retry statement is used to repeat the whole loop iteration from the start.

The retry statement is used inside a loop.

Syntax:

retry  

Comments

Leave a Reply

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