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
while Loop in C
The while loop executes a block of code repeatedly as long as a specified condition is true. It's ideal when you don't know the exact number of iterations needed.
while Loop Syntax
while (condition) {
// code to be executed
}#include <stdio.h>
int main() {
int i = 1;
printf("Numbers from 1 to 5:\n");
while (i <= 5) {
printf("%d ", i);
i++; // Important: increment to avoid infinite loop
}
printf("\n");
return 0;
}Practical Examples
#include <stdio.h>
int main() {
int number, sum = 0;
printf("Enter numbers (0 to stop):\n");
scanf("%d", &number);
while (number != 0) {
sum += number;
printf("Current sum: %d\n", sum);
printf("Enter next number: ");
scanf("%d", &number);
}
printf("Final sum: %d\n", sum);
return 0;
}Avoid Infinite Loops
Always ensure the loop condition will eventually become false. Update the control variable inside the loop.