C break statement
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 10; i++) {
if (i == 5) {
break;
}
printf("%d ", i);
}
return 0;
}
Explanation:
Include the standard input-output library (
stdio.h
).Define the
main
function.Declare an integer variable
i
.Start a
for
loop with the initialization ofi
to 1, conditioni <= 10
, and incrementi
after each iteration.Inside the loop, check if
i
is equal to 5 using theif
statement.If the condition is true, execute the
break
statement, which terminates the loop immediately.If the condition is false, print the value of
i
usingprintf
.End the
for
loop.Return 0 to indicate successful program execution.