Cags
Contributor
What is the best way of getting out of a nested loop (using c#), I know that you can exit a single Loop with the break; command,
but I'm unsure of the best way of exiting a nested loop, this is the way I'm currently doing it.
Is this the best approach, I remember reading somewhere that the goto command isn't particularly good coding practice, but I don't know of any other obvious way to exit.
C#:
for(int i = 0; i < iCount; i++)
{
if(RequirementMet) // situation on which I want to exit
break;
}
but I'm unsure of the best way of exiting a nested loop, this is the way I'm currently doing it.
C#:
for(int i = 0; i < iWidth; i++)
for(int(j = 0; j < iHeight; j++)
if(ReqruirementMet)
goto BreakLoop;
BreakLoop:
Is this the best approach, I remember reading somewhere that the goto command isn't particularly good coding practice, but I don't know of any other obvious way to exit.