Meaning
A loop may be defined as a smaller program the can be
executed several times in a main program.
3 ways to do loop in C++
i.while
ii.do....while
iii.for
a)'while' loop
Format 'while':
while
(condition)
{
statement
(s);
}
explanation
With the while statement, the condition is first tested and if the
condition is TRUE then the statement
or statements within the loop will be
executed and if the condition is first tested is FALSE the loop will
not be
executed at all. The condition
will be tested repeatedly until the condition is false.
b)'do...while' loop
Format 'do....while':
do
{
statement
(s);
} while
(condition);
EXPLANATION
The do while loop checks the condition at the end of the loop. This means that the statement or statements
inside the do while loop will be executed again if the condition is TRUE. If the condition is FALSE, the do while loop will not be executed.
c)'for' loop
Format:
for (start expression ; test expression; count expression)
{
statements;
}
EXPLANATION:
C evaluates the start expression before the loop begins. Typically, the start expression is an
assignment statement ( such as ctr=1;)
but it can be legal expression you specify. C looks at and evaluates the start
expressions only once, at the top of the loop.


