Loops
are one of the most important of the languages like C and C++. They have
greatly reduced the drudgery of the programmers and developers which would
otherwise have made the programming of a software system or application more
hectic. The necessity of the loops cannot be ignored when it comes to the
repetition of a particular executable statement or a block of statements in a
program.
In other words,
Say we
have the below written statement in C++ programming language that we need to print only one time:
“hello!
Welcome to C++ programming”
To
print it one time we shall write the code like this:
Cout<<”hello!
Welcome to C++ programming\n”;
Say
now you need to print this statement a 100 times! What you are going to do-
write the above C++ statement a 100 times? No! Certainly not! This is unfeasible and a complete waste of time! So what is the alternative that we
have? Yes of course we have the “loops”.
Using loop we will have to write only
a small code instead of writing that C++ statement again and again for 100
times. Using loop we shall write like this:
For(
int i = 1; i <=100; i++ )
{
Cout<<”hello!
Welcome to C++ programming\n”;
}
The
above loop is a for loop and it will the statement that we wish to be printed
100 times. See to how much extent our task has been reduced! This would not
have been possible without loops.
Loops generally are classified based on their
types namely in to:
- The while loop
- The for loop
- The do – while loop
But
based up on their structure, they are classified in to two types:
- Structured loops and
- Unstructured loops
This
article is all about the unstructured loops. We shall discuss them in detail.
The Unstructured Loops
- The
unstructured loops can be defined as the loops that are void of a single header
or a node in the control flow graph that has all the nodes dominating the whole
loop body.
- The main problem that arises with these unstructured loops is of
managing them.
- Managing them is such a hectic task.
- For analyzing the
unstructured loops the programmers, developers and researchers have come up
with so many ways but none of them seems to be so efficient.
- One of the ways is
to use a control flow graph along with the scope graph corresponding to the
function containing the unstructured loop to be analyzed.
- This method involves
attaching of each and every iteration counter with each of the loop header.
- Attaching
the iteration counters in such a way can cause over estimation of the control
flow.
- So to overcome this problem, the iteration counters are attached to each
basic block and this helps a great deal in achieving a lot of flow information.
Even this way results in some disadvantage!
- Therefore another method of
managing the unstructured loops has been developed.
- Another method has been
developed for transforming the unstructured loops in structured ones.
- If one
looks at the unstructured loop with a view of the control flow graph they seem
to have entry edges to one or more than one node all over the loop.
- In another
way we can say that an unstructured consists of parts of several different
loops.
- Several structured loops can also be merged in to an unstructured loop
with the help of a code size optimizing compiler.
- A straight way has been
developed for the elimination of the unstructured loops which is creating a
scope with a single header for each entry of the loop.
No comments:
Post a Comment