While Loop

Programming

This program demonstrates the while loop, which executes a block of code repeatedly as long as a condition is true.

Implementation

#include <iostream>

int main() {
    int i = 1;
    int max_count = 5;

    std::cout << "Max Count: " << max_count << std::endl;
    while (i <= 5) {
        std::cout << "Count: " << i << std::endl;
        ++i;
    }
    return 0;
}

Key Concepts

Output

Max Count: 5
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5