-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex32.rb
More file actions
31 lines (30 loc) · 702 Bytes
/
ex32.rb
File metadata and controls
31 lines (30 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
the_count=[1,2,3,4,5]
fruits=['apples','oranges','pears','apricots']
change=[1,'pennies',2,'dimes',3,'quarters']
#this first kind of for-loop goes through a list
#in a more tranditional style found in other languages
for number in the_count
puts "This is count#{number}"
end
#same as above,but in a more Ruby style
fruits.each do |fruit|
puts "A fruit of type: #{fruit}"
end
#another style
change.each{|i| puts "I got #{i}"
puts i}
elements=[]
(0..5).each do |i|
subelements=[]
(0..5).each do |j|
subelements<<i*j
end
elements<<subelements
end
elements.each_index do |x|
z=elements[x]
z.each_index do |y|
puts "elements#{x}#{y}=#{elements[x][y]}"
end
end
p elements