From: Stuart Clarke Date: 2010-09-04T19:39:34+09:00 Subject: Ruby looping Hey, I have a quick query regarding loops, I am reading a CSV file take the information from the first line of the CSV file and calling an object which does some stuff, then I want to move on to the next line in the CSV file and continue this process until I have done every line. My code is as follows: require 'csv' file = "H:\\13936 _ Project HS\\extra tiff work\\test\\rename.csv" #path to CSV file def renameFile(oldID, newID) DO SOME STUFF end d = CSV.open(FILE, "r") #Open the as CSV d.each do |setA, setB| #2 columns of data next oldID = setB.to_s.strip newID = setA.to_s.strip[/.*(?=\..+$)/] renameFile(oldID, newID) #Call our object end end The above code does what I want it to but it very slow and gets slower the bigger the CSV file, because it seems to go through each line every time we are in the loop, when I only want it to go through the next line in the CSV file. I basically need it to do: line A CALL OBJECT skip line A do line B CALL OBJECT skip line A and line B do line C CALL OBJECT etc etc Any help is appreciated. -- Posted via http://www.ruby-forum.com/.