Choose a correct statement about C language break; statement.a)A singl...
The correct statement is:
1. A single break; statement can force execution control to come out of only one loop.
Explanation:
- In C language, a break; statement is used to exit the nearest enclosing loop (or switch statement) in which it is placed. It does not affect any outer loops if there are nested loops. Therefore, a single break; statement only forces the control to exit the innermost loop.
View all questions of this test
Choose a correct statement about C language break; statement.a)A singl...
Explanation:
Break statement in C language:
- The break statement in C language is used to bring the control out of a loop.
- It is commonly used in switch statements and loops like for, while, and do-while.
Limitation of break statement:
- A single break statement can force execution control to come out of only one loop.
- It cannot break out of multiple nested loops at once.
Example:
c
#include
int main() {
int i, j;
for(i = 1; i <= 3;="" i++)="">
for(j = 1; j <= 3;="" j++)="">
if(i == 2 && j == 2) {
break; // This will only break out of the inner loop
}
printf("%d %d\n", i, j);
}
}
return 0;
}
In the above example, when i is 2 and j is 2, the break statement will only exit the inner loop and resume execution of the outer loop. It cannot break out of both loops simultaneously.