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 traditional style found in other languaguesfornumberinthe_countputs"This is count #{number}"end# same as above, but in a more Ruby style# this and the next one are the preferred# way Ruby for-loops are writtenfruits.eachdo|fruit|puts"A fruit of type: #{fruit}"end# also we can go through mixed lists too# note this is yet another style, exactly like above# but a different syntax (way to write it).change.each{|i|puts"I got #{i}"}# we can also bulid lists, first start with an empty oneelements=[]# then use the range operator to do 0 to 5 counts(0..5).eachdo|i|puts"adding #{i} to the list."# pushes the i variable on the *end* of the listelements.push(i)end# now we can print them out tooelements.each{|i|puts"Element was: #{i}"}
the_count=[1,2,3,4,5]the_count.eachdo|number|puts"This is count #{number}"endelements=[](0..5).eachdo|i|puts"adding #{i} to the list."# pushes the i variable on the *end* of the listelements<<iend