0Pricing
C Academy · Lesson

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 — 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, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

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.

Looping Structures — illustration 1

2

The for Loop

The for loop repeats code a fixed number of times.

Syntax:

for (initialization; condition; update) { // Code to execute }

3

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;
}

4

The while Loop

The while loop repeats code while a condition is true.

Syntax:

while (condition) { // Code to execute }

5

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;
}

6

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);

7

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;
}

8

9

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.

10

Summary

In this lesson, you learned:

  • How to use for, while, and do-while loops.
  • The differences between each type of loop.
  • How to prevent infinite loops.

Next, we will explore logical and comparison operators in C!

Looping Structures — illustration 10

Frequently asked questions

Is the “Looping Structures” lesson free?

Yes — the full text of “Looping Structures” is free to read here on the web, and the C Academy course includes 3 lessons in total. 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.

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; this is — lesson 2 of 3, so you can start here or from the beginning and move at your own pace.

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

  1. Conditional Statements
  2. Looping Structures
  3. Logical and Comparison Operators
← Back to C Academy