Subscribe once and get notified the moment something relevant to your career is published. No spam, no noise.
Start your programming journey with one of the most powerful and foundational languages — C. This comprehensive course is designed for absolute beginners as well as intermediate learners who want to build a solid understanding of programming using the C language. Whether you're preparing for college-level programming, cracking technical interviews, or planning to explore systems or embedded development, this course covers everything step-by-step. Through hands-on examples, real-world practice problems, and structured explanations, you’ll learn how to write clean and efficient C code — from your first printf() to advanced data structures and memory management.
In programming, loops are used to execute a block of code multiple times until a specified condition is met. C provides three main types of loops: for, while, and do-while. Mastering loops allows you to build powerful and efficient logic for repetitive tasks.
for LoopUsed when the number of iterations is known beforehand.
for (int i = 1; i <= 5; i++) {
printf("Iteration %d\n", i);
}
This will print:
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
while LoopUsed when the number of iterations is not known and depends on a condition.
int i = 1;
while (i <= 5) {
printf("Value = %d\n", i);
i++;
}
do-while LoopExecutes the block at least once, then checks the condition.
int i = 1;
do {
printf("i = %d\n", i);
i++;
} while (i <= 5);
| Loop Type | Condition Checked | Use Case |
|---|---|---|
| for | Before iteration | Known iteration count |
| while | Before iteration | Unknown iteration count |
| do-while | After iteration | At least one execution needed |
A loop inside another loop. Used for pattern printing and 2D arrays.
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
printf("%d ", j);
}
printf("\n");
}
while (1) {
printf("This will run forever unless you break it.\n");
}
break; – exit from the loop immediatelycontinue; – skip current iteration and go to the nextfor (int i = 1; i <= 5; i++) {
if (i == 3) continue;
printf("%d ", i);
}
// Output: 1 2 4 5
Suppose UdaanPath wants to list top 10 trending courses on the homepage:
for (int i = 0; i < 10; i++) {
printf("Course #%d: Learn Programming\n", i + 1);
}
for, while, and do-while.for for known iterations, while for conditional, and do-while when code must run at least once.break and continue provide more control within loops.In the next chapter, we’ll explore Functions in C — how to declare, define, and use functions, including recursion.