Information Technology Reference
In-Depth Information
is interrogated and if it has a value of 0, program control is transferred to the label
next-step .
Otherwise control goes to the label
start-read .
Because of this logic, the next statement can never be reached as the if-then-else
statement has forced a branch to one of two places and it will either get to
next-step
or
start-read .
It can never get to the statement following the
end-if .
This line is dead code and there is no reason to leave it in the program. Sometimes people
write code this way but the extra line only confuses those looking at the program. On
other occasions a program may have been written without any dead code but someone
modifies it and in so doing creates these lines of meaningless logic, which can never be
executed. Changes were made that forced this scenario and whoever did them should also
have deleted the dead code. It's not necessary to keep it there since it will only take
someone longer to read the program and realize that this code is unreachable.
Now consider another group of statements:
If file-switch = 0
go to next-step
else
if file-switch = 1
go to start-read
end-if
end-if
screen (1,7) “file switch: ” file-switch
In this case you will agree that the last line can be executed. This would be true if the
field
file-switch
has a value greater than 1. But now suppose that in our program this field will only be 0
or 1. At this point the last line is once again unreachable as before. You couldn't tell this
fact unless you had knowledge of what values the field
file-switch
could be.
Let us consider one more set of statements.
read acctfile
start:
if acct-status = 0
print “account number ” account-number
go to start
else
Search WWH ::




Custom Search