Looping
Looping :-
Looping is a condition, in which a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop consists of two part, one known as body of the loop and the other is known as control statement.
The control statement checks the specified condition and then performs the repeated execution of the statements contained in the body of the loop. i.e. control statement is a looping's part that tests wheter the given condition is satisfying or not, if it is satisfiying then it directs the flow control to the body of the loop to b executed, until the specified condition do not gets false.
Body of the loop is the part of looping which contains the packet of command line, which gets executed when the given condition in control statements satisfies.
A looping process include following four steps :-
i) Setting and initialization of a condition variable.
ii) Execution of the statements in the loop.
iii) Test for a specified value of the condition variable for execution of the loop.
iv) Incrementing, decrementing, or updating the condition variable.
Depending on the position of the control statement in the loop, there are two types of loops :-
i) Entry controlled loop or pre-test loop :- In entry controlled loop, the control conditions are tested before start the execution of loop. If the conditions are not satisfied, then the loop will not be executed.
Flow chart of pre-test loop |
ii) Exit controlled loop or post-test loop :- In exit controlled loop, the control conditions are tested after the completion of the execution of the loop. Therefore the body is executed unconditionally for the first time.
Flow chart of post-test loop |
The C programming language supports three constructs for performing loop operations. :-
1. The while statement.
2. The do statement.
3. The for statement.
we will later discuss about these three looping statements.
Comments
Post a Comment