Notes / C / Loops

Loops in C — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Loops Loops let you repeat a block of code multiple times without rewriting it.

Syntax

syntax
for (init; condition; update) { }
while (condition) { }
do { } while (condition);

Example

c
#include <stdio.h>

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

Output

output1 2 3 4 5

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Interviewers love asking for the difference between while and do-while — the key is that do-while guarantees at least one execution.
Back to notes Read full lesson →