-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Sunday 22 March 2015

Concept of loops in C++

Today I am here with the most awaiting topic of C++,Loops.

There would be many definitions in your mind about loops and probably you might be confused about the actual concept.
So,the simple definition of loops is repetition of something.This could be either variables,constants,program statements of a block of code.


Suppose you want to write "Hello world" for 50 times.What would you do?
Will you write cout<<"Hello world"; for 50 times?

Yeah,this is a method but surely it is very time-consuming.

Loops are very useful in this type of condition.

To repeat a statement 50 times,you will use a loop and surely you will save your time as well.

So,there are mainly three type of loops in C++.

1.While loop

2.Do-while loop

3.For loop

While and do-while loops are used in a condition when we do not know in advance how many times we want to repeat a block of code or a particular statement,etc.

For loop is used in a condition when we know in  advance how many times we want to repeat a block of code or a particular statement,etc.

The examples of this topic will be discussed in the next blogs inshallah.

No comments:

Post a Comment