diff options
author | Gabriel Halley <ghalley@pindropsecurity.com> | 2015-10-07 15:26:25 -0400 |
---|---|---|
committer | Gabriel Halley <ghalley@pindropsecurity.com> | 2015-10-07 15:26:25 -0400 |
commit | 3b0bc74c568d88ea30dbca94b8312381d61fe3de (patch) | |
tree | 3216fc9910bed6e86f73c72dc0267d9e61b5bc26 /ruby.html.markdown | |
parent | f4c13bc6963a79bf419f78a554c5abf3bd7a5bd8 (diff) |
ruby each with index
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r-- | ruby.html.markdown | 6 |
1 files changed, 6 insertions, 0 deletions
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}" |