I suck at recursion, and I need some help understanding where I'm
going wrong here.

I have a script that reads a file, then creates an excel form file.
Here's the program.

puts "Enter file name"
filename = gets.chomp

puts "Enter carton size"
carton_size = gets.chomp

out_file = File.new("C:/test/inner workings.xls", "w+")
out_file.write("Carton number \t Carton quantity \t Card number \n")

file_size = IO.readlines(filename).size
total_cartons = (file_size.to_f / carton_size.to_f).ceil
i = 0
sequence = 1

in_file = File.open(filename)

unless in_file.eof?

  (i..(carton_size.to_i - 1)).each do |number|
    record = in_file.readline
    out_file.write("#{sequence}\t#{total_cartons}\t#{record[7, 19]}
\n")
  end

  sequence += 1
  if sequence > total_cartons
    break
  end
end


The problem I am running into, is it works fine until the sequence +=
1 part.
the output looks like
1 \t 7 \t 1234 1234 1234
1 \t 7 \t 1234 1234 1235

then right before
2 \t 7 \t 1234 1234 1300
it says "Done!" and closes.

out_file.close
puts "Done!"



I hope this makes sense enough for me to get some help.

Thanks,
~Jeremy