Euclid's algorithm implemented iteratively