Looping Structures
Understand different types of loops (for, while, and do-while), their use cases, and how to avoid infinite loops.
Looping Structures is a free C Academy lesson on CoddyKit. This is lesson 2 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 3 lessons in total.
Looping Structures in C
Loops are used to repeat a block of code multiple times.
In this lesson, you will learn about for, while, and do-while loops.

The for Loop
The for loop repeats code a fixed number of times.
Syntax:
for (initialization; condition; update) {
// Code to execute
}Example: for Loop
This program prints numbers from 1 to 5 using a for loop.
#include <stdio.h>
int main() {
for (int i = 1; i <= 5; i++) {
printf("%d\n", i);
}
return 0;
}The while Loop
The while loop repeats code while a condition is true.
Syntax:
while (condition) {
// Code to execute
}Example: while Loop
This program prints numbers from 1 to 5 using a while loop.
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
}
return 0;
}The do-while Loop
The do-while loop always executes the code at least once before checking the condition.
Syntax:
do {
// Code to execute
} while (condition);Example: do-while Loop
This program prints numbers from 1 to 5 using a do-while loop.
#include <stdio.h>
int main() {
int i = 1;
do {
printf("%d\n", i);
i++;
} while (i <= 5);
return 0;
}Avoiding Infinite Loops
An infinite loop runs forever if the condition never becomes false.
Example:
while (1) {
printf("This loop runs forever!\n");
}
Always ensure there is a way to exit the loop.
Summary
In this lesson, you learned:
- How to use
for,while, anddo-whileloops. - The differences between each type of loop.
- How to prevent infinite loops.
Next, we will explore logical and comparison operators in C!

Learn C with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 39
- Lessons
- 144
Frequently Asked Questions
Is the “Looping Structures” lesson free?
Yes — the full text of “Looping Structures” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO. The C Academy course includes 3 lessons in total.
What will I learn in “Looping Structures”?
Understand different types of loops (for, while, and do-while), their use cases, and how to avoid infinite loops. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 3.
How long does the “Looping Structures” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Conditional Statements
- Looping Structures
- Logical and Comparison Operators