What are the different loops in C programming language?
loops
On this page
For Loop
#include <stdio.h>
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 5; i++) {
printf("%d\n", i);
}
return 0;
}
Output
1
2
3
4
5
While Loop
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}
return 0;
}
Output
1
2
3
4
5
Do-While Loop
#include <stdio.h>
#include <stdio.h>
int main() {
int i = 1;
do {
printf("%d\n", i);
i++;
} while (i <= 5);
return 0;
}
Output
1
2
3
4
5