This looks too much like a homework assignment for me to see writing it for you as a favor. However, a couple tips should not defeat your learning curve traverse. You need to keep all 5 files open, then in each pass of the loop read a line from each of the files to become a datum for each of 5 (or 4?) columns. No break needed. In programming, the usual way to express using N similar objects similarly is to place them into an N-length array and iterate over it. For your solution, this will mean two, nested loops: An outer one iterating over file lines/DB rows; and an inner one iterating over the files. You will need separate N-long iteration loops to open and close the files.