Control flow

4.4 - For loop


For loop is another kind of loop that works as a shorthand for a common use case of loop.

So for loop looks like this:

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

That for loop is the same as this code using a while loop:

int i = 0;

while (i < 10)
{
    std::cout << i << std::endl;

    i++;
}

Basically a for loop is usually:

for (initializer; condition; incrementer/decrementer)
{
    inside loop code;
}

Task

Your task is to use the for loop to print from 1 to 10000.

#include <iostream> int main() { // Start your program here }