From the source code below, Is there a way to get out of the overlapped repeat door at once using break?
int main(){
for(int i=0; i<A; i++){
//...
for (int j=0 ; j<B; j++) {
//...
for (int k=0; k<C; k++) {
if (D) {
break; // here
}
//...
}
//...
}
//...
}
}
In Java or other languages, you can name loop and solve it C++ doesn't have that capability.
It can't be a break
You can solve it by writing goto
or by creating flag
.
The code below is to create endflag
to exit the repeated statement overlapped with conditional statements
int main(){
bool endflag = 0;
for(int i=0; i<A; i++)
{
for (int j=0 ; j<B; j++)
{
if (C) {
endflag = 1;
break;
}
}
if (endflag) {
break;
}
}
}
© 2024 OneMinuteCode. All rights reserved.