GO TO And DO statements

GO TO Statement
1) Unconditional GO TO statement
Unconditional GO TO statement is used to jump from one statement number to the other in that program.
The general form of an unconditional GO TO statement is:
GO TO n
where n is the statement number of an executable statement. Blanks between GO and TO are optional.
Example:
1) GO TO 50
2) GO TO 10
Here 50 and 10 are statement number.
GO TO 0 (0 is invalid statement number).
GO TO,10 ( , is not allowed).
Statement number should be an integer which also should be not too long.
2) Computed GO TO statement
In this Computed GO TO statement the transfer or control depends on the value of an integer variable which is a part of this statement.
The general form of a computed GO TO statement is:
GO TO (n1, n2,……,np), i
where: i is an integer expression
n1, n2,……np are the statement numbers of an executable statement that appears in the same program unit as the computed GO TO statement. The same statement number may appear more than once in the same computed GO TO statement. i expresses the ith statement number.
Example:
GO TO (5, 10, 20,1), B
This means here the value of the integer variable in this computed GO TO may be either supplied or calculated within the program.
3) Assigned GO TO Statement
The form of an assigned GO TO statement is: GO TO i [(n1, n2,…)]
where: i is an integer variable name
n1, n2,…..are the statement numbers of an executable statement that appears in the same program unit as the assigned GO TO statement. The same statement number may appear more than once in the same assigned GO TO statement.
Assigned GO TO Statement is rarely used i.e. Its uses is limited.
DO Statement
A DO statement is used to specify a loop, called a DO-loop.
There are two DO-loops:
· Active
· Inactive
A DO-loop becomes active only when its DO statement is executed.
After being active, the DO-loop becomes inactive only when:
· Its iteration count is tested and determined to be zero.
· A RETURN statement is executed within its range.
· Control is transferred to a statement that is in the same program unit and is outside the   range of the DO-loop, or
· Any STOP statement in the executable program is executed.
The general form of a DO statement is:
DO n i = n1 , n2, [,n3]
where: n is the statement number of an executable statement and this n is also known as terminal statement. Comma between i is the name of an integerreal, or double precision variable, called the DO-variable n1, n2 , and n3 are either integer, real, or double precision expression.
Note: The terminal statement of a DO-loop must not be an unconditional GO TO, assigned GO TO, arithmetic IF, block IF, ELSE IF, ELSE, END IF, RETURN, STOP, END or DO statement.
Example:
DO 100 I = 2, L
Here DO 100 I =2, L commands that all statements following it up to and including statement 100 be executed L times, from I =2 to I = L.
Following are valid DO statements:
DO 100 I =2, 20
DO 20 K = 1, L+3 etc.
Invalid DO statements are:
DO 100 I = 1.6 ( . is not allowed)
DO 30 I =15 ( I =15 is wrong)
Scroll to Top