DECISION MAKING AND LOOPING
DECISION MAKING AND LOOPING
INTRODUCTION
2. Execution of the statements in the loop.
3. Test for a specified condition for exection of the loop.
4. Incrementing the counter.
2.The do - while statement
3. The for statement
Note: Use the hyperlink to directly to navigate into the topic.
INTRODUCTION
It
is possible to execute a segment of a program repeatedly by introducing a
counter and later testing it using the if statement and goto statement. It
forms a loop. In looping, a sequence of statements are executed until some conditions for termination of the
loop are satisfied. A program loop consists of two segments, one known as the body
of the loop and the other known as the control statement. The
control statement tests certain conditions and then directs the repeated
execution of the statements contained in
the body of the loop. Depending on the position of the control statement in the
loop, a control structure may be classified either as the entry-controlled
loop or as theexit-controlled loop.
In
entry-control loop, the control conditions are tested before the start of the
loop execution. If the conditions are not satisfied, then the body of the loop
will not be executed. In the case of an exit-controlled loop,the test is
performed at the end of the body of the loop and therefore the body is executed
unconditionally for the first time.
A looping
process, in general, would include the following four steps:
1. Setting and
initialization of a counter.2. Execution of the statements in the loop.
3. Test for a specified condition for exection of the loop.
4. Incrementing the counter.
The C language
provides for three loop constructs for performing loop operations. They are:
1.The while statement
2.The do - while statement
3. The for statement
Note: Use the hyperlink to directly to navigate into the topic.
Comments
Post a Comment