From 3b0bc74c568d88ea30dbca94b8312381d61fe3de Mon Sep 17 00:00:00 2001 From: Gabriel Halley Date: Wed, 7 Oct 2015 15:26:25 -0400 Subject: ruby each with index --- ruby.html.markdown | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 7fe34336..51c4b9d8 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -261,6 +261,12 @@ hash.each do |key, value| puts "#{key} is #{value}" end +# If you still need and index you can use "each_with_index" and define an index +# variable +array.each_with_index do |element, index| + pust "#{element} is number #{index} in the array" +end + counter = 1 while counter <= 5 do puts "iteration #{counter}" -- cgit v1.2.3