Over the last decade many techniques for optimizing relational queries have been developed however the problems of translating these set-oriented query specifications into other forms for efficient execution has received little attention. this paper presents algorithm that translates algebra-based query specifications into iterative programs for an efficient execution while the course level operates on sets or tuples the generated programs manipulate tuples as their basic objects the algorithm incorporates techniques which have been developed in the areas of functional programming and program transformation