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
Nested Loops In C++ Programming Language We have studied about loops in C++ programming language. There are three looping statements that we worked with so far i.e, while loop, do-while loop, and for loop. We know that we use loops when we want to repeat or iterate some piece of code according to our programming logic and requirement. Now the first question arises that what is a nested loop. At this point so far we already have knowledge about loops. Nested loops are nothing they are just a loop that is placed or resides completely inside another loop. In simple words it is a loop inside another loop. And remember one important point, the inner loop completes all of its iterations every single time the outer loop runs once. Basic Syntax Of Nested Loops In C++ Programming Language Now we will look at syntax of for loop , while loop , and do-while loop . Below is a syntax of for nested for loop in C++ programming language Below is a syntax for nested ...
Get link
Facebook
X
Pinterest
Email
Other Apps
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 of for loop in C++ Programming Language
for (Initialization; Condition; Increment)
{
//Code to be executed.
}
Basic Working Of For Loop in C++ Programming Language
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.
Simple Programming Examples of for loop in C++ programming Language
In the first programming example we 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.
This program will simply print numbers from 1 to 10 in console screen.
In the second programming example we will simply take two inputs the first one is the TableNumber and the second one is the TableLength. This program will simply prints the table of any given number and upto some specific range of numbers like from 1 to 10 or from 1 to 20, etc.
And with the for loop we will simply use TableLength number to specify the condition upto specific table length. If we enter TableNumber = 2 and TableLength = 10 then this program will print the table of number 2 from 1 to 10 i.e,
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
.
.
.
2 * 10 = 20
Congratulations like always we have successfully executed the for loop program in C++ programming language.
How to Run C project in Visual Studio Community 2022 Many people think we cannot write c code in the visual studio community. but this is completely not true, yes we can create a C file and run C code in Visual Studio 2022 let us see how we can achieve it. 1) Open Visual Studio 2022 First of all, we are going to open Visual Studio 2022. 2) creating a new project Then we are going to create a new project by clicking create new project button. 3) choosing a project template: Create a new project window that will appear in front of you. From this window select an empty project template with C++ symbol on it. Then push the next button. 4) configure your project A new window will appear in front of you with the heading Configure your new project. In this window, you can select your project and solution name. And also the location of your project. then click the Create button. 5) New project created: On clicking the create button a C++ project is go...
While Loop in C++ Programming Language We have discussed about the entry-controlled loop or pre-tested loop previously in our blog posts. These statements or loops are used to repeat a piece of code for a specific number of times as per our program requirement. We have studied about the for loop already. Today in this blog post we are going to study about the while loop in C++ programming language. And we will look at how this while loop actually works and how we can stop it by making some condition false so that the loop might not run infinitely. We use while loop in C++ program when the number of iterations is not known in advance and depends on the condition. When we know exactly that how many times a loop should run then we use the for loop instead of while loop. Basic Syntax Of While Loop in C++ Programming Language Basic Working Of While Loop In C++ Programming Language Now we are going to discuss about the basic working of while loop in C++ programming....
If and if-else statements in the C++ programming language In this blog post we will look at the basic working of if and if-else statement in C++ programming language. These if and if-else statements are also referred as conditinal statements in programming languages. But today we will study them under the context of C++ programming. In C++ programming language we use if and if-else to run a specific peace of code under one condition and another peace of code for some different condition. We also refer them as decision statements . Types of if statements in C++ programming language If we talk about types of if statements there are mainly four types 1) if statement 2) if-else statement 3) if else-if ladder statement 4) nested if statements But in this blog post we will cover the if and if-else statements. Syntax of if statement if(condition) { //code to be executed here } Simple if coding example ...
Comments
Post a Comment