Control Flow

Loops

Repeat code multiple times.

For Loop

for (int i = 0; i < 5; i++) {
    std::cout << i << std::endl;
}

While Loop

int count = 0;
while (count < 5) {
    std::cout << count << std::endl;
    count++;
}

Do-While Loop

int count = 0;
do {
    std::cout << count << std::endl;
    count++;
} while (count < 5);

Range-Based For Loop (C++11)

int arr[] = {1, 2, 3, 4, 5};
for (int num : arr) {
    std::cout << num << std::endl;
}
Visualizer
for loop iteration
1
2
3
4
5
✓ Loop completed

Interactive Visualization

c
Loading...
Output
Run execution to see output...