V
viza
Hi!
Suppose I have
int i,j,k;
for(i=0;i<I;++i){ /* loop 1 */
for(j=0;j<J;++j){ /* loop 2 */
for(k=0;k<K;++k){ /* loop 3 */
if(test){
break;
}
}
}
}
then when test comes to be true, it will break out of loop 3, increment j
and continue in loop 2. How can I break out of all three? Is there a way
to break out of say loop 3 and 2 and continue the top level loop? This
would be break(2); in php. I vaguely remember in javascript you can label
a loop to break out of a paticular one.
Is there a way to control these, structures (and others, like switch etc)
like this in C, or do I need to use temporary variables, like
int i,j,k;
for(i=0;i<I&&!broken;++i){ /* loop 1 */
for(j=0;j<J&&!broken;++j){ /* loop 2 */
for(k=0;k<K&&!broken;++k){ /* loop 3 */
if(test){
broken=1;
break;
}
}
}
}
?
Thanks
Tom Viza
Suppose I have
int i,j,k;
for(i=0;i<I;++i){ /* loop 1 */
for(j=0;j<J;++j){ /* loop 2 */
for(k=0;k<K;++k){ /* loop 3 */
if(test){
break;
}
}
}
}
then when test comes to be true, it will break out of loop 3, increment j
and continue in loop 2. How can I break out of all three? Is there a way
to break out of say loop 3 and 2 and continue the top level loop? This
would be break(2); in php. I vaguely remember in javascript you can label
a loop to break out of a paticular one.
Is there a way to control these, structures (and others, like switch etc)
like this in C, or do I need to use temporary variables, like
int i,j,k;
for(i=0;i<I&&!broken;++i){ /* loop 1 */
for(j=0;j<J&&!broken;++j){ /* loop 2 */
for(k=0;k<K&&!broken;++k){ /* loop 3 */
if(test){
broken=1;
break;
}
}
}
}
?
Thanks
Tom Viza