D
dgiaimo
I was wondering what style of programming is preferred when continuing
an outer loop from within an inner loop. As far as I see it, there
are two possibilities, which I have given in pseudo-code below. The
first follows the strict, structural programming rule of only using
breaks and continues to control flow, while the second uses gotos.
Personally I prefer the second since it seems clearer, seems like it
would be easier to optimize, and doesn't use an artificial control
variable. What do you think?
void function(void)
{
int foundIt;
while(<condition1>)
{
foundIt = 0;
while(<condition2>)
{
if(<condition3>)
{
foundIt = 1;
break;
}
}
if(foundIt)
{
continue;
}
....
}
}
void function2(void)
while(<condition1>)
{
while(<condition2>)
{
if(<condition3>)
{
goto continueouter;
}
}
goto skipcontinue;
continueouter:
continue;
skipcontinue:
....
}
}
an outer loop from within an inner loop. As far as I see it, there
are two possibilities, which I have given in pseudo-code below. The
first follows the strict, structural programming rule of only using
breaks and continues to control flow, while the second uses gotos.
Personally I prefer the second since it seems clearer, seems like it
would be easier to optimize, and doesn't use an artificial control
variable. What do you think?
void function(void)
{
int foundIt;
while(<condition1>)
{
foundIt = 0;
while(<condition2>)
{
if(<condition3>)
{
foundIt = 1;
break;
}
}
if(foundIt)
{
continue;
}
....
}
}
void function2(void)
while(<condition1>)
{
while(<condition2>)
{
if(<condition3>)
{
goto continueouter;
}
}
goto skipcontinue;
continueouter:
continue;
skipcontinue:
....
}
}