What is the purpose of the 'break' statement in C?
A. End the program
B. Skip the loop
C. Exit a function
D. Exit a loop
Answer: Option D
Solution (By Examveda Team)
The purpose of the 'break' statement in C is to exit a loop. When 'break' is encountered within a loop (such as 'for' or 'while' loop), it immediately terminates the loop and continues with the next statement after the loop's body.So, the correct answer is:
Option D: Exit a loop
Here's an example of using the 'break' statement to exit a loop in C:
for (int i = 1; i <= 10; i++) {
if (i == 5) {
break; // Exit the loop when i is equal to 5
}
printf("%d ", i);
}
Join The Discussion