Statement may be executed sequentially, selectively or iteratively. Every programming language provides constructs to support sequence, selection or iteration. Every programmer should have knowledge of these constructs for using selection statement.
Sequence
Sequence construct means the statements are being executed sequentially. This represents the default flow of control as shown in below image.
Every Java function execution begins with its first statement then each statement in turn is executed (sequence construct). When the final statement of the function is executed, the function is done. This programming construct specifies the normal flow of control in a program and is the simplest one.
Selection
The selection construct means the execution of statement depending upon a condition-test. If a condition evaluates to true, a course-of-action (a set of statements) is followed otherwise another course-of-action (a different set of statements) if followed. Selection construct is also called decision construct because it helps in making decision about which set of statements is to be executed.
Iteration
Iteration construct means repetition of a set of statements depending upon a condition-test. Till the time a condition is true a set of statements are repeated again and again. As soon as the condition becomes false the repletion stops. The iteration construct is also called looping construct.
The set of statements that are repeated again and again is called the body of the loop. The condition on which the execution or exit of the loop depends is called the exit condition or test condition.
No comments:
Post a Comment