Home Tutorials Jruby For Loop example in JRuby



For Loop example in JRuby
Posted on: September 29, 2008 at 12:00 AM
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

     

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

     

Related Tags for For Loop example in JRuby:
crubyoopiofor-looploopjrubyvithisooshowforieexampletoexamsheilsectionuseinmoutjhowxaxampsishallmplpressthshoavstabpleplprono


More Tutorials from this section

Ask Questions?    Discuss: For Loop example in JRuby  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.