문제

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

도움이 되었습니까?

해결책

It's simple do-while loop:

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

// else code here
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top