-3

I'm trying to replace this block of code with any other loop (I thought of while and do, but for some reason I didn't get the logic down entirely.

repeat:
   ... 
   if (condition)
   {
     goto repeat
   }
   else
   {
     ...
   }

Can someone help me out with the logic here? I saw a few posts about replacing goto statements, but they only relied on a single if with no else's.

The thing that is messing my thinking up is the fact that there isn't anything inside the if statement, just the goto. If I were to try to translate it to a while statement, it leaves me with this:

while (condition)
{
   // don't know what goes here since there is nothing but goto in the if statement
}
// else stuff

Thanks

AzureFrost
  • 67
  • 2
  • 8

1 Answers1

3

It's simple do-while loop:

do
{
    // code between "repeat:" and the if here
} while (condition);

// else code here
Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263