Information and technology, FahadTheITGuy, programming languages, web development, desktop development, C, C++, C#, visual basic, HTML, CSS, javascript, jQuery, MS SQL server, in this blog, we will learn different programming languages and implement them with examples, we are also going to learn web development in asp.net, asp.net core, asp.net MVC, asp.net core mvc, we also learn about databases in ms SQL server, we will also cover databases, data structures, data mining, and wisdom mining
For Loop In C++ Programming Language
Get link
Facebook
X
Pinterest
Email
Other Apps
-
For Loop In C++ Programming Language
In Programming languages looping statements are used with the help of these looping statements we can repeat some block of code according to our requirement of the program. In C++ programming language we also use these looping statements, these looping statements are also referred as controlled structure.
In this blog post we are going to cover for loop statement which is used to execute a block of code repeatedly for a specific number of times. The for loop is "entry controlled" or "pre-tested" loop which means that the condition is checked before the code inside the loop ever runs. We use for loop when we know exactly how many times the loop will going to run.
Basic syntax and working of for loop in C++ programming language
Syntax of for loop
for (initialization; condition; increment)
{
// code to be executed here.
}
Working of for loop in C++ programming language
Now let us look at the basic syntax of for loop in C++ programming language. Starting with a for key word followed by opening and closing round brackets and with in these round brackets we can see three expressions.
1) initialization
2) condition
3) increment
As by now we know that loops are used to repeat a block of code. And if the numbers of iterations is fixed it is preferred to use the for loop than while or do-while loops. The for loop consists of three main parts, first part is the initialization, second part is condition, and the third part is the increment i.e, for (Initialization; Condition; Increment)
In the initialization part we simply declare and initialize a variable like int i = 1, in the condition part we simply make some condition that might be true or false like i <= 10, and the last part of the for loop is the increment part which is i++. In the last part we can either increment or decrement the value of i variable.
And after that we have opening and closing curly brackets and with in these brackets we can write the piece of code or the logic for the for loop. Just keep one thing in mind that when ever we are sure that how many times we want to repeat a piece of code then we should use for loop instead of while or do while loop.
Simple Programming Examples of for loop in C++ programming Language
Programming Example 1
#include<iostream>#include<conio.h>usingnamespace std;
void main()
{
for (int i = 1; i <= 10; i++)
{
cout << i << endl;
}
_getch();
}
Explanation of coding example 1
In the first programming example we have created a for loop and declared and initialized the value of variable i like this int i = 1. After that we simply write a condition and specifies that this loop will run untill value of i is less or equal to 10 like this i <= 10. And at last part of the for loop we simply increment the value by adding 1 like this i++ which is equal to i = i + 1.
for (int i = 1; i <= 10; i++)
After that we have opening and closing curly brackets with in which we have simply printed the values from 1 to 10 using the value of i variable with cout statement.
cout << i << endl;
This program will simply print numbers from 1 to 10 in console screen.
Programming Example 2
#include<iostream>#include<conio.h>usingnamespace std;
void main()
{
int TableNumber, TableLength;
cout <<"Enter Table Number = ";
cin >> TableNumber;
cout <<"Enter Table Length = ";
cin >> TableLength;
for (int i = 1; i <= TableLength; i++)
{
cout << TableNumber <<" * "<< i <<" = "<< TableNumber * i << endl;
}
_getch();
}
Explanation of coding example 2
In the second programming example we will simply take two inputs the first one is the TableNumber and the second one is the TableLength.
How to Download and Install Microsoft visual studio community 2022 for free As a programmer or developers, we all know that to start learning coding or developing applications we need an Integrated Development Environment (IDE). These IDE's are also software applications, on which we can write code and develop applications. Visual Studio is an IDE developed by Microsoft. Today we are going to see how to download and install Microsoft Visual Studio Community 2022 for free. In order to download and install visual studio community 2022 first we have to download and get installer for Microsoft visual studio from official website of Microsoft visual studio website. Once you have the installer then you can select workload packages as per your domain or your area of expertise i.e, web development, desktop development, ios development, and game development, etc. which Microsoft Version To Download and Install Now let us look at that which version of visual studio should ...
Hello World Program In C Programming Language In todays blog post we will look at C programming language. We will cover some basic introduction about C programming language. And then we will see what are the uses of C programming in real world. And after that we will simply make a hello world program in C programming language in visual studio community 2026 IDE. Basic Introduction Of C Programming Language C programming language is a general purpose programming language. It is procedural and structured programming language. The C language is in use for nearly 50 years. It was created by Dennis Ritche at AT&T Bell labs in 1970s . C programming language is very powerful, it helps us developing Operating Systems, Databases, Applications, etc. C programming language is used to develop system applications that directly interact with hardware devices like drivers, kernels, etc. Uses Of C Programming Language The C programming language is very versatile and powerf...
If and if-else statement in C programming language In todays blog post we will cover the concept of conditional statements in C programming with simple examples, so that our audience can understand it in an easy manner. These conditional or control statements are used to control the flow of execution, based on some predifined conditions. Conditional statements are one of the basic builiding blocks of any programming language and the same is true with respect to C programming language. Today we will cover two of the most basic decision making statements or control statements which are known as, 1) if statement 2) if-else statement Before diving deep into C programming coding examples, let us look at the basic syntax and basic working of the two conditional statements. Basic syntax of if statement in C programming language if (condition) { // code to be written here. } If we look at the above if statement coding syntax we can see that, we started with the i...
Comments
Post a Comment