C++ Display a text 5 times

#include <iostream>

int main() {
    for (int i = 0; i < 5; ++i) {
        std::cout << "Display this text 5 times" << std::endl;
    }
    return 0;
}

Explanation:

  1. #include <iostream>: Includes the input-output stream header file, allowing the program to perform input and output operations.

  2. int main() { }: Defines the main function where the execution of the program starts.

  3. for (int i = 0; i < 5; ++i) { }: Initiates a loop that will run five times, starting with i equal to 0 and ending when i becomes equal to 4. The loop increments i by 1 in each iteration.

  4. std::cout << "Display this text 5 times" << std::endl;: Outputs the text "Display this text 5 times" followed by an endline character (std::endl) to the standard output (usually the console). This line is executed five times due to the loop.

  5. return 0;: Indicates successful termination of the main() function and the program overall.