×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to demonstrate the 'redo' statement in the loop

Last Updated : December 15, 2025

Problem Solution

In this program, we will use the "redo" statement to repeat the current iteration of the loop. The redo statement has executed the body of the loop without evaluating the condition of the loop.

Program/Source Code

The source code to demonstrate the "redo" statement in the loop is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate the 
# "redo" statement in the loop

cnt = 0;

while(cnt < 5)  
  print cnt,": Hello World\n"  
  cnt = cnt + 1;   
  redo if cnt == 5 
end

Output

0: Hello World
1: Hello World
2: Hello World
3: Hello World
4: Hello World
5: Hello World

Explanation

In the above program, we used the "redo" statement to repeat the current iteration of the loop. The redo statement has executed the body of the loop without evaluating the condition of the loop.

Here we repeated the loop iteration when the value of cnt is 5 without checking the loop condition.

Ruby Looping Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.