for statement in c++
#include <iostream>
int main() {
for (int i = 0; i < 5; ++i) {
std::cout << "Iteration: " << i << std::endl;
}
return 0;
}
Explanation:
#include <iostream>
: Include the input/output stream header file to enable the use of the standard input/output functions.int main() {
: Define the main function, the entry point of the program.for (int i = 0; i < 5; ++i) {
: Start of a for loop. The loop initializes an integer variablei
to 0, executes the loop body as long asi
is less than 5, and incrementsi
by 1 in each iteration.std::cout << "Iteration: " << i << std::endl;
: Output the current value ofi
along with the text "Iteration:" to the standard output.}
: End of the for loop.return 0;
: Indicate successful execution of the program and terminate the main function.}
: End of the main function.