How To Write Hello World Program In C++ Programming Language

Image
  How To Write a Hello World Program In C++ Programming Language In this post we will look at how a C++ program works. We will try make the example as simple as possible for the beginners so they can easily understand the basics of C++. We will write a simple C++ hello world program in C++ programming language which is considered as the very first program in almost every programming language. A Brief Introduction to the C++ Programming Language C++ is an object oriented programming language and it is an extension to C programming language. C++ is a general purpose programming language and it is also a case-sensitive language. C++ is very powerful programming language it has features of both low level and high level programming languages, and that is why it is called mid level programming language. Hello World program in C++ programming language Above is an example of a simple Hello World program in C++ programming language. Now let us look at the code, and I will take you...

Nested Loops in C Programming Language

 Nested Loops in C Programming Language

In programming languages, we have control statements or looping statements which are the following,

1) while-loop

2) do-while loop

3) for loop




we have seen loop implementation one at a time i.e., one loop type implemented in the program. Now we will look at how to use the nested loops in the C programming language. The first thing to keep in mind is what we mean by the term nested loop. The main idea behind nested loops is to place a loop inside another loop.

In this article, we are going to look at nested for loops in the C programming language. As we previously discussed we can use a loop inside another loop. So today we are going to look at how we can use a for loop inside another for loop

Remember that if we have two for loops one for loop inside another for loop, and if both the loops are set to three iterations, then for each iteration of the outer loop the inner loop will execute three times i.e. if the outer loop runs three times the inner loop will run the total of 9 times let us look at the syntax of nested loop.


Basic Syntax of Nested Loop:

outer_loop

    {

        Inner_Loop

            {

            // Inner loop statements

            }

        // Outer loop statement

    }


Another important point to keep in mind is that we can use any loop inside another loop i.e. we can use all loops inside for loop i.e. a for loop, a while loop, and a do-while loop inside a for loop. In the same way, we can use any loop inside any loop statement.

Now we are going to look at a simple example of a nested for loop in this example both loops will execute three times let us look at the example below.




Explanation of above program:

In the above example, there are two for loops, one for loop inside another for loop. So this is a nested for loop. If we look at this program the outer for loop has variable i and it will be executed 3 times because i is equal to 1 and the loop will run until i becomes less or equal to 3 according to the outer for loop condition i.e. i<=3.

And also the inner loop will be executed 3 times as we look at variable j=1 and j<=3. But keep this important point in mind for every outer loop iteration the inner loop will run 3 times i.e. if the outer loop with variable i will run 3 times then for every outer loop iteration the inner loop will run 3 times. So the total number of times the inner loop will be executed is 9 times.

Thus the execution of this simple program will result in printing 9 numbers with 3 rows and 3 columns. The output of this program would be something like this,



Congratulations we have successfully executed the nested for loop program.


Comments

Popular posts from this blog

How if else-if else ladder statement works in C program.

How to add two numbers in C programming language