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