C Tutorial — Learn C Programming
Key takeaway: This free C tutorial teaches you systems programming from scratch — variables, pointers, arrays, functions, structs, and memory management — with practical code examples you can compile and run.
C is a general-purpose, procedural programming language created in 1972. It is used for operating systems, embedded systems, game engines, and performance-critical applications. This tutorial is for beginners, CS students, and developers who want to understand how computers work at a low level.
Last updated: September 2026
break and continue Statements
The break and continue statements provide additional control over loop execution. They allow you to exit loops early or skip specific iterations.
break Statement
The break statement immediately exits the current loop.
#include <stdio.h>
int main() {
printf("Numbers from 1 to 10, but stop at 6:\n");
for (int i = 1; i <= 10; i++) {
if (i == 6) {
break; // Exit the loop when i equals 6
}
printf("%d ", i);
}
printf("\nLoop ended!\n");
return 0;
}continue Statement
The continue statement skips the rest of the current iteration and moves to the next iteration.
#include <stdio.h>
int main() {
printf("Odd numbers from 1 to 10:\n");
for (int i = 1; i <= 10; i++) {
if (i % 2 == 0) {
continue; // Skip even numbers
}
printf("%d ", i);
}
printf("\n");
return 0;
}Practical Example
#include <stdio.h>
int main() {
int secret = 7;
int guess;
int attempts = 0;
int maxAttempts = 3;
printf("Guess the number (1-10). You have %d attempts.\n", maxAttempts);
while (attempts < maxAttempts) {
printf("Enter your guess: ");
scanf("%d", &guess);
attempts++;
if (guess < 1 || guess > 10) {
printf("Please enter a number between 1 and 10.\n");
attempts--; // Don't count invalid input
continue;
}
if (guess == secret) {
printf("Congratulations! You guessed it in %d attempts!\n", attempts);
break; // Exit the loop on correct guess
} else if (guess < secret) {
printf("Too low! ");
} else {
printf("Too high! ");
}
printf("Attempts remaining: %d\n", maxAttempts - attempts);
}
if (attempts >= maxAttempts && guess != secret) {
printf("Game over! The number was %d.\n", secret);
}
return 0;
}Key Points
- break: Completely exits the loop
- continue: Skips to the next iteration
- Both statements only affect the innermost loop they're in
- Use them to make your code more efficient and readable