Information Technology Reference
In-Depth Information
The statement following the
define
will be executed 10 times, that is until
line-counter
is greater than 9. The variable
line-counter
will start out as 0 and
loop: line-counter = line-counter + 1
will result in 1 being added to the field and 1 will now be the new value of
line-counter .
A check on the value of the variable is now done and since
line-counter
is not greater than 9, a branch will be made to the label
loop .
Then
line-counter
will become 2 and the check will be done again and once more a branch is made to the
label
loop .
As the program continues to be executed,
line-counter
will become 3, 4, 5, 6, 7, 8, 9 and then 10 and now since
line-counter
is greater than 9, a branch will be taken to the label
end-program
and there is no further action.
This statement at the label
loop
is a way to increment a field, such as we had in our program when we needed to keep
track of the lines printed in order to know if a new set of headings was needed. Of course
we could increment this field by 2 or 3 or even a negative number if we desired. If our
increment statement had been
loop: line-counter = line-counter - 2
note than we would have the following values for
line-counter :
2, 4, 6, 8, and 10. If you think it should be -2, -4, -6, -8, -10 because we are subtracting 2,
recall that the variable
line-counter
is defined integer, with no provision for the sign. Thus the first increment will do the
subtraction but since the computer has no place for a negative sign, the
line-counter
will be 2 at first. Eventually it will get to 10 and we will branch to the label
end-program .
If we have
Search WWH ::




Custom Search