From: Vikas Sarin Date: 2009-07-21T17:48:32+09:00 Subject: Re: create a variable number of loop Would recursive methods be allowed in Ruby? regards, Vikas Sarin -----Original Message----- From: chen_li3@yahoo.com [mailto:chen_li3@yahoo.com] Sent: Tuesday, July 21, 2009 2:10 PM To: ruby-talk ML Subject: create a variable number of loop Hi all, I want to create a variable number of loop based on the input: if the input is 1, I will create a loop ( I call it 1-loop); if the input is 2 , I will create a nested loop( 2-loop); if the input is 3, I will create a loop of loop of loop (3-loop); if the input is 4, I will create a 4-loop, so on and so on. How I can do that? Thanks, Li array=%W{A B C D} #input is 1 array.each do |e1| puts e1 end #input is 2 array.each do |e1| array.each do |e|2 puts e1+e2 end end #input is 4 array.each do |e1| array.each do |e2| array.each do |e3| array.each do |e4| puts e1+e2+e3+e4 end end end end -- Posted via http://www.ruby-forum.com/.