The ideal way would be to re-factor your code so that you no longer need such a complicated nested-loop structure. Depending on what the rest of your code looks like, your b
and c
loops may be candidates for becoming individual functions, if not the entire a
loop.
Since it looks like loops b
and c
iterate over adjacent ranges, why not combine them and reduce your loop nesting a bit?
for (int a = 1; a <= 100; a++) //loop a (main loop)
{
int count = 1000;
while (count <= 3000) // combined loops 'b' and 'c'
{
if (count <= 2000)
{
// Old loop 'b' code
if (b == 1555)
goto fullbreak;
}
else
{
// Old loop 'c' code
...
}
count++;
}
}
fullbreak:
You can also use a condition variable instead of the goto
. If you want to break out of the old b
loop but still process the old c
loop, simply set count = 2001
inside the old b
loop code.
Ideally, you would at least be able to re-factor this to something more like
for (int a = 1; a <= 100; a++) //loop a (main loop)
{
if (process_inner_loop(pass, required, args))
break;
}
where the function process_inner_loop
wraps up your original two loops and returns non-zero if you want to break out of the enclosing loop. Now, instead of using goto
or condition variables, you can simply return 1;
.