while loop replaceable with 'foreach'