×

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 'next' statement in the loop

Last Updated : December 15, 2025

Problem Solution

In this program, we will use the "next" statement to skip statement execution within the loop body. The "next" statement is similar to the 'continue' statement in the C language.

Program/Source Code

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

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

for cnt in 1..10   
   if cnt == 5 then   
      next   
   end   
   print cnt," ";   
end

Output

1 2 3 4 6 7 8 9 10

Explanation

In the above program, we used the "next" statement to skip the execution of statements within the body of the loop. Here we skipped the printing of number 5 using the "next" statement.

Ruby Looping Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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