Substituted 'loop' function for 'for' function