Return to Snippet

Revision: 80600
at March 21, 2020 23:25 by chrisaiv


Updated URL
https://www.chrisjmendez.com/2007/10/21/ruby-how-to-iterate-through-an-array/

Updated Code
https://www.chrisjmendez.com/2007/10/21/ruby-how-to-iterate-through-an-array/

Updated Description
https://www.chrisjmendez.com/2007/10/21/ruby-how-to-iterate-through-an-array/

Revision: 4081
at October 21, 2007 20:01 by chrisaiv


Updated Code
#A. Create an array
names = %w[chris sandy josie billy suzie]

#B. Find the length of the array and iterate through it 
names.length.times do |i|
  puts i.to_s + " " + names[i]
end

Revision: 4080
at October 21, 2007 20:01 by chrisaiv


Initial Code
#A. Create an array
names = %w[chris sandy josie billy suzie]

#Find the length of the array and iterate through it 
names.length.times do |i|
  puts i.to_s + " " + names[i]
end

Initial URL

                                

Initial Description
For all of you actionscripters out there, this example is the Ruby equivalent of writing for(i in array){trace(i);} or for(i = 0; i < array.length; i++){trace(i);}

Initial Title
How to iterate through an array in Ruby

Initial Tags
ruby

Initial Language
Ruby