Instead of writing the same sequence structure containing a lot of duplicated code, a better way to repeatedly perform an operation is to write the code for the operation once, and then place that code in a structure that makes the computer repeat it many times as necessary, this can be done with a repetition structure, which is more commonly known as a loop or iterative statement.
The Iterative statements (loops) is one of the most common programming structures. It is important since algorithms often need to repeat certain segments over and over.
Iterative statements (loops) allow a set of instructions to be executed or performed several times until certain conditions are met. It can be predefined as in the for loop, or open ended as in while and do while.
The looping statement is a program instruction that repeats some statement or sequence of statements in a specified number of times.
CONDITION-CONTROLLED and COUNT-CONTROLLED LOOPS
The way that a count-controlled loop works is simple: the keeps a count of the number of times that it iterates, and when the count reaches a specified amount the loop stops. A count controlled loop uses a variable known as a counter variable, or simply a counter, to store the number of iterations that it has performed.
Using the counter variable, the loop typically performs the following three actions: initialization, test, and increment:
Initialization: Before the loop begins, the counter variable is initialized to a starting value. The starting value that is used will depend on the situation.
Test: The loop tests the counter variable by comparing it to a maximum value. If the counter variable is less than or equal to the maximum value, the loop iterates. If the counter variable is less than or equal to the maximum value, the loop iterates. If the counter is greater than the maximum value, the program exits the loop.
Increment: To increment a variable means to increase its value. During each iteration, the loop increments the counter variable by adding 1 to it.
repetitive control structure process