loop in c++ and it's types while , do while, for loop...

        loop in c++.

loops

In simple word the loops means repeat. in c++ loops means a repeated of a block or grouped of statement of program  for a specific number of times is called loops in c++. It is also know as iterative or repetitive structure in c++. In sequential structure all statement are executed once. On the other hand, conditional structure may execute or skip a statement on the basic of the given condition. In some situations, it is required to execute a statement or number of statements repeatedly. loops structure are very useful to iterate our collection of item or perform a specific task multiple times.

Uses of loops statement.

        loops are basically used for two purpose. 
  • To execute a statement or number of statement for a specific number of times such as displaying the user name on the screen for 10 times.
  • To use a sequence of values such as displaying the numbers from 1 to 10.

Types of loops in c++

There are three  types of loops available in C++ ,
this are as follows.
  1. while loop
  2. do.. while loop
  3. for loop

  • while loop
The while loop is the type of loop in program it repeatedly execute a statement or group of statement as long  as a given condition is true.
The while loop is the simplest loop of C++ language, This loop executes one or more statement while the condition is true . it is useful when the number of iterations is not known in advance. 

syntax

                The syntax of while loop is as follows.
                    while (condition) 
                                statement;
                        
while____                It indicates the start of while loop.
condition____         The condition is given as a relational expression . The statement is executed only if the given condition is true. The statemen tis never executed if the condition is false. 

statement ____      It represent the body of the loop. if the body of loop contains more than one statement , they are written in curly braces {   }.

The syntax of the while loop if the statement are more than one 
            while(condition)
                    { statement 1
                        statement 2;
                            statement 3;
                                 .
                                .
                                  .  }

  • for loop.
Now the for loop is the second type of loop . The for loop is execute a section fo code for a fixed number of times . it is usually used when we known the exact number of execute before the entering the loop how many times we want to execute the code in the loop.
  A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
         syntax
            for( initialization, condition, increment/decrement )
{  
    statement 1;
    statement 2;
    statement 3;
  initialization __ It specifies the starting value counter variable.
condition __ the statement is executed only if the given condition is true otherwise the statement will be skips.
inc/dec ___ increment is used to jump on option forward.
decrement
 is used to jump backward.

  • do while loop.
The do while loop is the third type of loops in c++ program. This loop execute one or more statement while the given condition is true. The condition in this loop checked after the body of loop. that's why it is executes at least one .

syntax
    do 
        { statement 1;
            statement 2;
            statement 3;
while ( condition)



loop and it's types in c++
loop and it's types 



.