0

I am attempting to add retries to a function but I'm unsure if the following is a safe way to do this

void start() 
{
    int count = 0;
    while (true)
    {
        if (!configure())
        {
            count++;
            if (count == 2)
            { 
                 //error handling

                return;  
            }
         }
         count = 0;
         break;
    }

//do other stuff

}

Will this work?

user1984300
  • 101
  • 3
  • 15
  • 1
    This will help you, take a look: https://stackoverflow.com/questions/1563191/cleanest-way-to-write-retry-logic – Kyle Jun 02 '17 at 18:45
  • 2
    This code will try to configure and if it fails set count to 1, set count to 0, break and end. So...no? – Milster Jun 02 '17 at 18:46
  • @Milster if I add an `else` statement before resetting count to zero and breaking will that work? – user1984300 Jun 02 '17 at 19:07
  • @user7827715 Please have a look at the 2 posted links. They will help you. But to answer your question, Yes, that could work. In future just try the code and step through it with your debugger. A huge part of programming is learning how to understand and analyze code. – Milster Jun 02 '17 at 19:11

0 Answers0