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:
#include <iostream>
: Includes the input-output stream header file, allowing the program to perform input and output operations.int main() { }
: Defines the main function where the execution of the program starts.for (int i = 0; i < 5; ++i) { }
: Initiates a loop that will run five times, starting withi
equal to 0 and ending wheni
becomes equal to 4. The loop incrementsi
by 1 in each iteration.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.return 0;
: Indicates successful termination of themain()
function and the program overall.