Table of Contents
In this tutorial, we will discuss the for loop in C++ programming language
In the programming language, looping statements are used to repeat a particular block of code.
In the C++ programming language, “for statement” is used to repeat a block of code until the particular condition is satisfied.
In the programing language, Generally , loops are used to repeat a specific group of code until some condition is satisfied
There are three types of loops used in C++ language
here, we are going to learn how to use the for loop in C++ language
for(init-expression; condition-expression; update-expresion;) { //statement(s);}
For loop, flow chat in C++ |
#include <iostream>
using namespace std;
int main()
{
int counter;
for(counter=1; counter<=10; counter++)
{
cout <<counter<< “—> Hello this is for loop” << endl;
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
program 2
#include <iostream>
using namespace std;
int main()
{
for(int i=0; i<=2; i++)
{
cout<<i<<endl;
}
// Output: 0
int i;
for(i=0; i<=2; i++) {
cout<<i<<endl;
}
}
When the above code is compiled and executed, it produces the following result:
program 3
using namespace std;
int main()
{
int i; //define a loop variable
for(i=0; i<=5; i++) //starting value. condition 0 to 5. increment
{
cout << i <<” “; //print var i and space
//cout<<endl; //print new line
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
program 4
This program used ton print – 5 number serious
using namespace std;
int main()
{
int i; //define a loop variable
for(i=0; i<=5; i++) //starting value. condition 0 to 5. increment
{
cout << i <<” “; //print var i and space
cout<<endl; //print new line
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.