Replaced two for-loops in DeviceUtil into foreach loops.

Lets us omit a variable declaration.