When I'm training in a friendly gym, sometimes I know I can only beat up to the first or second trainer in the gym. Also I see no reason to needlessly put my Pokemon to 1 HP when I know I will lose.
After I've beaten one or two trainers, does giving up during the battle of the third trainer forfeit the XP and prestige I would've earned for beating the first trainers?