Uploaded by mahati.1412

PPT MES

advertisement
INTRODUCTION
TYPES
WORKING
EXAMPLES
CONCLUSION
WHAT IS A LOOP?
Loops are used to execute the block of
code several times according to the
condition given in the loop.
It means it executes the same code
multiple times until the given condition is
true.
It helps to traverse the elements of an
array.
WHILE LOOP
DO WHILE LOOP
FOR LOOP
While loop is the pre test loop. It first test
the specified conditonal expression and as
long as the conditional expression is true
the loop body statement will be executed.
While loop is also known as entry control
loop.
It is used when we don’t know the number
of it is needed to be executed.
START
CONDITION
FALSE
TRUE
LOOP BODY
END
SYNTAX AND EXAMPE OF WHILE LOOP
SYNTAX
EXAMPLE
While(condition)
{
//statement;
incr/decr;
}
int i=1;//initilization
While(i<=5)//condition
{
Printf(“%d”,i);//statemnet
i++;//incr/decr
}
Do while loop is a post test loop.It is
simillar to while loop,except that it
executes the body atleast once wether
the condition is true or false and
terminates when the test expression is
evaluvated to zero.
It executes the condition at the end of
loop.
It is known as exit cotrol loop.
START
LOOP BODY
CONDITION
TRUE
FALSE
END
SYNTAX AND EXAMPLE FOR DO WHILE LOOP
SYNTAX
Do
{
//statement;
Incr/decr;
}
While(condition);
EXAMPLE
Int i=10
Do
{
Printf(“%d”,i);
i--;
}
While(i>=1);
Return 0;
For loop enables us to perform n
number of steps together in one line.
In for loop a loop variable is used to
control the loop.
It execute the statement of the
program several times until a given
condition returns false.
It is used to traverse array,linked list
etc.
START
INITIALIZATION
FALSE
CONDITION
TRUE
LOOP
LOOPBODY
BODY
INCR/DECR
END
SYNTAX AND EXAMPLE OF FOR LOOP
SYNTAX
For(initialization;condition;
incr/decr)
{
//statement;
}
EXAMPLE
For(int i=1;i<=10;i++)
{
Printf(“%d”,i);
}
Download