Replace 'for' loop with 'foreach'