mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-24 18:11:38 +00:00
ruby each with index
This commit is contained in:
parent
f4c13bc696
commit
3b0bc74c56
@ -261,6 +261,12 @@ hash.each do |key, value|
|
|||||||
puts "#{key} is #{value}"
|
puts "#{key} is #{value}"
|
||||||
end
|
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
|
counter = 1
|
||||||
while counter <= 5 do
|
while counter <= 5 do
|
||||||
puts "iteration #{counter}"
|
puts "iteration #{counter}"
|
||||||
|
Loading…
Reference in New Issue
Block a user