Wednesday, October 21, 2015

Programming Language Constructs used in Java

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.
So the conclusion is every programming language must provide all these constructs as the sequential program execution in inadequate to the problems we must solve. Java also provides statements that support these constructs.

No comments:

Post a Comment