Loops
Loops
Here are comprehensive notes on Loops in C programming, covering types, syntax, and
examples:
🌀 Loops in C Programming
📘 Introduction
🔁 Types of Loops in C
1. for loop
2. while loop
3. do...while loop
1. ✅ for Loop
Syntax:
Example:
#include <stdio.h>
int main() {
for(int i = 1; i <= 5; i++) {
printf("i = %d\n", i);
}
return 0;
}
2. 🔄 while Loop
Syntax:
while(condition) {
// Code to be executed
}
Example:
#include <stdio.h>
int main() {
int i = 1;
while(i <= 5) {
printf("i = %d\n", i);
i++;
}
return 0;
}
3. 🔁 do...while Loop
Syntax:
do {
// Code to be executed
} while(condition);
Example:
#include <stdio.h>
int main() {
int i = 1;
do {
printf("i = %d\n", i);
i++;
} while(i <= 5);
return 0;
}
🛑 break
🔁 continue
💡 Nested Loops
A loop inside another loop.
Example:
🧠 Best Practices