S
Shawn
Hi,
I ran into a problem. I need to label a block and use "continue" to
control the program flow in certain conditions.
mainForLoop:
for(int i=1; i < 100; i++)
{
...
if(..)
{
...
continue mainForLoop;
}
else
{
...
}
} //end of for loop, also end of the block mainForLoop
The above code works fine and my program functions correctly. But I hope
to add brackets for block1. The compiler says it is error. My code looks
like:
mainForLoop:
{
for(int i=1; i<100; i++)
{
...
if(..)
{
...
continue mainForLoop; //ERROR: continue cannot be used outside of a
loop. Why?
}
else
{
...
}
} //end of for loop
} //end of block mainForLoop
What is the problem? Ideally, I like the syntax of the second version,
because it is clearer.
Thank you.
I ran into a problem. I need to label a block and use "continue" to
control the program flow in certain conditions.
mainForLoop:
for(int i=1; i < 100; i++)
{
...
if(..)
{
...
continue mainForLoop;
}
else
{
...
}
} //end of for loop, also end of the block mainForLoop
The above code works fine and my program functions correctly. But I hope
to add brackets for block1. The compiler says it is error. My code looks
like:
mainForLoop:
{
for(int i=1; i<100; i++)
{
...
if(..)
{
...
continue mainForLoop; //ERROR: continue cannot be used outside of a
loop. Why?
}
else
{
...
}
} //end of for loop
} //end of block mainForLoop
What is the problem? Ideally, I like the syntax of the second version,
because it is clearer.
Thank you.