Solving nested loops.