loops

C Loops

C Loops

Loops are used to repeat a block of code multiple times.

For Loop

#include 

int main() {
    for (int i = 1; i <= 5; i++) {
        printf("Count: %d\n", i);
    }
    return 0;
}
    

This program uses a for loop to print numbers from 1 to 5.

While Loop

#include 

int main() {
    int i = 1;
    while (i <= 5) {
        printf("Count: %d\n", i);
        i++;
    }
    return 0;
}
    

This program uses a while loop to print numbers from 1 to 5.