VOOZH about

URL: https://www.geeksforgeeks.org/ruby/ruby-redo-and-retry-statement/

⇱ Ruby redo and retry Statement - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Ruby redo and retry Statement

Last Updated : 17 Sep, 2019
In Ruby, Redo statement is used to repeat the current iteration of the loop. redo always used inside the loop. The redo statement restarts the loop without evaluating the condition again. Output:
2
3
4
5
6
7
8
9
10
11
12
13
14
Re-doing when x = 15
15
16
17
18
19
20
In above example, redo statement apply when x = 15.

retry Statement:

To repeat the whole loop iteration from the start the retry statement is used. retry always used inside the loop. Example #1: Output:
Iteration 0
Iteration 1
Iteration 2
Iteration 3
Iteration 3
Iteration 3
...
Example #2:
Comment
Article Tags:
Article Tags: