It's simple do
-while
loop:
do
{
// code between "repeat:" and the if here
} while (condition);
// else code here
Question
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
Solution
It's simple do
-while
loop:
do
{
// code between "repeat:" and the if here
} while (condition);
// else code here