Nested loops for simulation