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:

  1. Include the standard input-output library (stdio.h).

  2. Define the main function.

  3. Declare an integer variable i.

  4. Start a for loop with the initialization of i to 1, condition i <= 10, and increment i after each iteration.

  5. Inside the loop, check if i is equal to 5 using the if statement.

  6. If the condition is true, execute the break statement, which terminates the loop immediately.

  7. If the condition is false, print the value of i using printf.

  8. End the for loop.

  9. Return 0 to indicate successful program execution.