Cryptography Reference
In-Depth Information
if x<100 then {
swap x,k;
k=k+1}
else {
p=p+1;
swap x,k;}
swap x,k;
Loops Loops may be very handy devices for a programmer, but they
can often be an ambiguous obstacle when a program must
run in reverse. One easy example is the while loop often writ-
ten to find the last element in a string in C. That is, a counter
moves down the string until the termination character, a zero,
is found. It may be easy to move backward up the string, but it
is impossible to know where to stop.
Theproblemswithaloopcanbeeliminatedifthestructureis
better defined. It is not enough to give a test condition for the
end of the loop. Youmust specify the dependent variable of the
loop, its initial setting, and the test condition. When the loop
is reversed, the machine will run through the statements in the
loop until the dependent variable reaches its initial setting.
This structure is often not strong enough. Consider this loop:
i=1;
j=i;
while (i<2) do {
j=j+.01;
i=floor(j);}
The floor(x) function finds the largest integer less than or
equal to x . This function will execute 100 times before it stops.
If it is executed in reverse, then it will only go through the loop
twice before i is set to its initial value, one. It is clear that i is
the defining variable for the loop, but it is also clear that j plays
abigpart.
There are two ways to resolve this problem. The first is to warn
programmers and hope that they will notice the mistake before
they use the code to send an important message. This leaves
some flexibility in their hands.
Another solution is to further constrain the nature of loops
some more. There is no reason why they can't be restricted to
for loops that specify a counter that is incremented at each it-
eration and to map functions that apply a particular function to
Search WWH ::




Custom Search