For Loop example in JRuby

In previous section you have studied a lot about JRuby example. In this example we will show you how to use For-loop in JRuby.

For Loop example in JRuby

For Loop example in JRuby

     

In previous section you have studied a lot about JRuby example. In this example we will show you how to use For-loop in JRuby.

In this example we are showing you how to use for loop in JRuby. In Ruby "for-loop" is also different from the "for-loop" in Java. It has the syntax like :

 

 

 

 

for i in start_value .. end_value
  ................
  Statement 1
  Statement 2
 ..................
  end

 

Here is the example code of JRubyForLoop.rb as follows:

 

# Using for loop in JRuby

print "Use of for loop in JRuby \n"
  for i in 1..10
  puts "Value is => #{i}"
  end


Output
:

To run this example open console and type jruby command and filename on command prompt and you will get following output on your console as follows:

 

C:\JRuby>jruby JRubyForLoop.rb
Use of for loop in JRuby
Value is => 1
Value is => 2
Value is => 3
Value is => 4
Value is => 5
Value is => 6
Value is => 7
Value is => 8
Value is => 9
Value is => 10


Download Source Code