main loop for i = 1...n - 1 do