summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGabriel Halley <ghalley@pindropsecurity.com>2015-10-07 15:26:25 -0400
committerGabriel Halley <ghalley@pindropsecurity.com>2015-10-07 15:26:25 -0400
commit3b0bc74c568d88ea30dbca94b8312381d61fe3de (patch)
tree3216fc9910bed6e86f73c72dc0267d9e61b5bc26
parentf4c13bc6963a79bf419f78a554c5abf3bd7a5bd8 (diff)
ruby each with index
-rw-r--r--ruby.html.markdown6
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}"