you should break the loop when the condition is reached. most programming languages provide mechanismens to break a loop.
example language:
do{
player.performAction();
boolean playerHasWon = checkPlayerWinCondidtion();
if( playerHasWon){
//maybe perform other actions here, ut later and ultimatly...break
break; //breaks the loop here
}
opponent.performAction();
boolean opponentHasWon = checkOpponentWinCondition();
if(opponentHasWon){
break; //breaks the loop here
}
while(true);
not that you need an endless loop, just as an example...
anyway for your question: yes, you answered that thign already correct. you have to use if statements, that would be the proper way to do it... there are fancy ways of programming such stuff but in the end it is the right way to do it.