Flow Of Statements
Control statements in C++ comes into use when we need to repeatidly execute a block of statements.
Iterative Method- It cause statements to be executed zero or more times,subject to some loop-termination criteria.
Loops- A loop is a sequence of instructions that is repeated condition is reached.
- An operation is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number.
- Counter not Reached: If the counter has not reached the desired number, the next instruction in the sequence returns to the first instruction in the sequence and repeat it.
- Counter reached: If the condition has been reached, the next instruction “falls through” to the next sequential instruction or branches outside the loop.
There are mainly two types of loops:
- Entry Controlled loops: In this type of loops the test condition is tested before entering the loop body. For Loop and While Loop are entry controlled loops.
- Exit Controlled Loops: In this type of loops the test condition is tested or evaluated at the end of loop body. Therefore, the loop body will execute atleast once, irrespective of whether the test condition is true or false. do – while loop is exit controlled loop.

-
For Loop :-A for loop is a repetiton comtrol structure that allows us to write a loop that execute a specific number of times.
syntax:
for(initialisation expr; test expr; update expr)
{
statement(s);
}

- While Loop :- A loop repeatedly executes a set of statements untill a particular condition is satisfied.A while loop statement repeatedly executes a target statements as long as a given condition remains true.
syntax:
while(condition)
{
statement(s);
}
statement(s);
}
- Do-while Loop :- Unlike for and while loops,test the loop condition at the top of the loop,the do-while loop checks its condition at the bottom of the loop.A do-while loop is similar to a while loop, difference is that the do-while loop is guaranted to execute at least one time.
syntax:do
{
statement(s);
}while(condition);
Comments
Post a Comment