LOOP IN C++:
© The machaniem through whieh a siaioment or sat of statement
can be executed repeatedly is called loop
) [he slotements thot are executed repectedly ore called body of
foop.
The body af lop can be executad repeatedly for a specified
© ‘umber of times or until the given condition remains true
In c++ there are four types of loop as;
4) For loop
© 2) while loop
3) Do while loop.
- 4) Nested loop’—For loop
+ The “for” loop is used to execute a
Statement or set of statements repeatedly
for a specific numbers of times
* This loop [Link] known as counter loop,
Syntax of for loop
Forfinitialization;candition;increment/decrement}
{
Statements;
}
Next statement;
MeanThe “for"loop is executed as follows;
1)First initialization partis executed , It is executed only for the first time
When contral enters into the loop
2yAlter executing initialization pe
True,then body of loop is executed
the consti sated. if iis
3)Alter executing bedy of loop, increamentidecreament part is executed
increament/decreament partis last statement of body of “for loop.
Working of
Tar)Flow chart of for !oop.
False
Body of loop
Increament/decreament
\
— Next statement
@MuhamrExample
of for loop
#include
#include
Main();
{
Int n;
For (n=1;n<=10;n++)
cout <
#include
Main()
{
Int num;
Num=1;
While(num<=15)
t (num%3==0)
Cout<
#includesconio.h>
Main()
{
int =1;
Do
Cout<
#include
Main()
{
Int ui;
U=t;
‘While (u<=3)
{
Cout <