+1 @ xerzi.
The do/while loop is the best construct for this, IMO
Also you do not need a flag. Quite the opposite... with the goto approach, you have to pick a unique label name (you may find yourself with ugly, confusing names like 'loop1:', 'loop2:', etc), whereas with do/while you do not have to pick a name... the scope itself is enough to identify it.
1 2 3 4
|
label:
code();
if( condition )
goto label
|
is the same as:
1 2 3 4
|
do
{
code();
}while(condition);
|
The latter is more easily recognized by most people.
When you see a
do
statement, you immediately know some things:
1) You know the code is entering a loop. You do not necessarily know this when you see a
label:
statement. With a label, maybe the program jumps there from earlier in the function... or maybe the label is unused.
2) the code inside the loop is easily identifiable because it's within the following {code block}. This is actually huge.
Code blocks greatly improve clarity and organization. They also limit scope, which also helps keep things easy to follow. With a do/while loop, you can quickly see the entire loop because of the {block}.
With label/goto, you can't. Not only because of the lack of indentation and/or {code block}, but also because there's no scope limitation. There might be several gotos at various points in the function that jump to that label. You have no way of knowing without reading the entire function.