Loop structures:while loop,do-while loop,for loop
What is Looping structure in C++
Loop
There are three types of Loops:
- While Loop
- Do-While Loop
- For Loop
---------------------------------------------------------
while Loop:
This is the simplest loop of c++ language.This loop execute one or more statement while the given condition remains true.It is useful when the number of repetations not known in advence.Syntax:
while(condition)
statement;
compound statement syntax:
while(condition)
{
statement1;
statement2;
:
:
statementN;
}
---------------------------------------------------------
do while Loop:
In this loop the condition comes after the body of the program.This loop execute one or more statement while given condition tru.This is also an iterative loop.This loop is important when loop body must be executed at least once.In this loop semi-colon is also used after the condition as ' while(condition); 'Syntax:
do
{
statement1;
statement2;
statement3;
}
while(condition);
---------------------------------------------------------
For Loop:
For loop is also called counter-controlled loop.It is the most flexible loop.This loop execute one or more statement for a specified number of time.syntax:
for(initialization;condition;increment/decrement)
{
statement1;
statement2;
}
Loop structures:while loop,do-while loop,for loop
Reviewed by Alpha
on
3/14/2017 09:31:00 pm
Rating:
No comments: