Declare for loop controlling variable inside for loop - C++ Statement

C++ examples for Statement:for

Description

Declare for loop controlling variable inside for loop

Demo Code

#include <iostream>
using namespace std;
int main()//w ww  . j  ava  2  s .  c  om
{
   int  n = 0;
   // Get a number from the keyboard.
   cout << "Enter a number and press ENTER: ";
   cin >> n;
   for (int i = 1; i <= n; ++i){ // For i = 1 to n
      cout << i << " ";         //    Print i.
   }
   return 0;
}

Result


Related Tutorials