Similar Items: Loop Composition in Quantum Algorithms