Change to AND:
while ((playerhp > 0) && (enemyhp > 0))
I.e., you only do the while loop when both hp are positive. It either one of them is not, then the while loop exits.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!