c++ for and while loop

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char** argv) {

    int n=5;//Declares a variable n, and assigns a value 5 to it.
        
        
    cout << "Here begins the for loop.\n";
    for(int i=0; i<n; i++)
    {
        cout << "Loop: " << i << "\n";
    }

    cout << "Here begins the while loop.\n";
    
    int i=0;
    while(i<n)
    {
        cout << "Loop: " << i << "\n";
        i++;
    }
    return 0;
}

Output:

Here begins the for loop.
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4
Here begins the while loop.
Loop: 0
Loop: 1
Loop: 2
Loop: 3
Loop: 4

Search within Codexpedia

Custom Search

Search the entire web

Custom Search