Branching
of execution
There is some history associated with
the branching of control in computer programming. Your computer's hardware
probably provides supports for arbitrary branching, i.e., from any point
in the program to any other. However, it was found in the 1960s that arbitrary
branching was difficult to understand and test.
The result was the development of structured
programming principles limit the programmer to a small number of branch
types. Java enforces these principles strictly, except in error conditions
(we will investigate the way Java implements error handling through exceptions
in a later unit).
Java offers 3 kinds of branch of execution
flow:
-
subroutine calling
-
selection
-
iteration
Since all three kinds of statement control
the flow of execution, they are often referred to as control statements.
Subroutine calling is implemented via
method invocation. It is the process of getting the interpreter to execute
a method of an object. It consists of instructing the interpreter to remember
where it is at present, and to send a message to an object, resulting in
a (possibly inherited) method of that object being executed. When that
method has completed its execution, control of execution will return to
the original statement where the message was sent.
Selection is another word for 'choice'.
It is the process of selecting one of a number of different statements,
according to some condition. In Java, selections are implemented using
the if, if
.. else and
switch .. case statements.
Iteration is another word for 'looping'.
This simply means repeating some program statements a particular number
of times. In Java, iteration is implemented using the
while, do .. while
and for
statements.
Back
to top
RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex
University. All rights reserved.
webmaster@globalcampus.com.eg
|