Merge "Swap while loops with foreach where applicable"