The redo statement is used to repeat a block of code that has just been executed. It is often used to repeat the same method call, or a sequence of statements.
Ruby provides three different ways to use the redo statement. The first way is to use it as a conditional statement, where the condition is whether or not the Ruby program has executed the loop at least once. The second way is to use it as an unconditional command, so that any number of times can be executed. The third way is to use it with a block of code like other programming languages do with loops.
The redo statement can be used with three different forms:
redo # undoes the last change
redo x # undoes x changes
redo x, y, z # undoes x, y and z changes
The Redo statement in Ruby is used to repeat the current loop iteration. Inside the loop, redo is always utilised. The redo statement returns the loop to its previous state without re-evaluating the condition.
Share a personalized message with your friends.