replace loop with transform