I am writing a routine which has the following form:TRY AIF no success, BIF no success, RETRY AIF no success, throw errorIt's not trivial to extract either A or B into it's own routine, so what is most simple structure that will allow me to retry A without code duplication?Currently, I have a do..while that allows N retries:int retries = 1;do {    // DO A    if ( /*success*/ ) {        break;    } else if (retries > 0)  {        // DO B        if ( /*success*/) {            break;        }    } else {        // throw Error    }} while (retries-- > 0);This is ugly and not ideal as it implies that I might want to ever retry more than once, which I don't.  I will have to use a loop, but there has to be a more simple way that I'm not seeing.For context, this is code generated in Java, executing SQL statements to try an UPDATE first, then if no entry to update is found, INSERT, and if that command fails (concurrency, already created), try UPDATE again.
What is a good code pattern for single retry then error?
design patterns;algorithms