Replace some for loops with foreach

Change-Id: Id9e03ec66e55a110a1518aed7a162458b8079da9
Merge "Replace some for loops with foreach"