Anyone who is interested in a Fanuc macro for this problem may look into
WHILE loop inside G71