If current.compare(oldValue) == 0, you could assign newValue and break out of the loop.