C++ program to print 1 to 10 numbers using for loop
In this tutorial, we are going to learn how to print 1 to 10 numbers using for loop in C++. So we can print using for loop in an easy way without lengthy codes and for loop makes our task much easier.
Syntax
for(initialization; condition ; increment/decrement)
{
C++ statement(s);
}
For loop
This helps to iterate over a part of C++ code for a limited number of times as per our condition. For loop will run if the condition provided is true. The lop execution ends if the condition becomes place.
C++ Code: Print 1 to 10 numbers using for loop
#include <iostream> using namespace std; int main() { cout<<"The first 10 numbers are as follows: \n"; for(int i=1;i<=10;i++) //for loop used to increament each time loop runs. { cout<<i<<endl; } return 0; }
Output:
The first 10 numbers are as follows: 1 2 3 4 5 6 7 8 9 10
Explanation:
First, we will print the statement we require using cout. Then we will apply loop condition that the number should start from 1 and ends at 10 it increments every time till the condition in the loop is true. After that when they reach the limited condition ie till 10 the loop breaks. Then all the 10 numbers will be printed using cout.
Hope this tutorial was helpful!
If I use ” ” instead of End1;
int main()
{
int = i;
for (i =1; i <= 10; i++)
{
cout << i << " ";
}
return 0;
}