⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fstruct.gml

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 GML
📖 第 1 页 / 共 4 页
字号:
.exam begin
      I = 1
      DO WHILE( I .LE. 3 )
          J = 1
          DO WHILE( J .LE. 5 )
              PRINT *, MATRIX( I, J )
          END DO
      END DO
.exam end
.np
The above is equivalent to the following example which uses statement
numbers.
.keep 10
.exam begin
      I = 1
      DO 10 WHILE( I .LE. 3 )
          J = 1
          DO 20 WHILE( J .LE. 5 )
              PRINT *, MATRIX( I, J )
20        CONTINUE
10    CONTINUE
.exam end
.np
The next example demonstrates the use of a
.kw GO TO
statement to control execution of all or part of a DO-loop.
.keep 15
.exam begin
      I = 1
      DO WHILE( I .LE. 3 )
          J = 1
          DO WHILE( J .LE. 5 )
              PRINT *, 'INNER LOOP - J=', J
              IF( J .LE. 3 )GO TO 20
              PRINT *, 'J > 3'
20        END DO
          PRINT *, 'OUTER LOOP - J=', J
      END DO
.exam end
.np
A result of this example is that the character string
.mono J > 3
is printed 6 times (i.e., twice for each iteration of the outer loop).
Of course there is a much better way of coding this algorithm using
the IF-END IF construct.
The example is included to illustrate the behaviour of transfers of
control to an
.kw END DO
statement.
The following example is an equivalent algorithm to the one above but
the intent is much clearer.
.keep 10
.exam begin
      I = 1
      DO WHILE( I .LE. 3 )
          J = 1
          DO WHILE( J .LE. 5 )
              PRINT *, 'INNER LOOP - J=', J
              IF( J .GT. 3 )THEN
                  PRINT *, 'J > 3'
              END IF
          END DO
          PRINT *, 'OUTER LOOP - J=', J
      END DO
.exam end
.*
.keep 10
.section LOOP - END LOOP
.*
.mext begin
  LOOP    [: block-label]
      statement(s)
  END LOOP
.mext end
.np
This extension to FORTRAN 77 causes the statements between the
.kw LOOP
and
.kw END LOOP
statements to be repeated until control is transferred out of
the loop, usually by an
.kw EXIT
or
.kw QUIT
statement.
An optional block label may be specified (see the
.kw CYCLE,
.kw EXIT
or
.kw QUIT
statement for more information).
An example follows:
.keep 10
.exam begin
      LOOP
          READ *, X
          IF( X .EQ. 99.0 )EXIT
          PRINT *, X
      END LOOP
.exam end
.np
The above statements cause values to be read and printed, one to
a line, until the value 99.0 is read.
When variable
.id X
has this value, the logical expression in the
.kw IF
statement evaluates as true and the
.kw EXIT
statement causes a transfer of control to the statement following the
.kw END LOOP
statement.
The
.kw EXIT
statement is discussed in more detail in a later section.
.*
.keep 10
.section WHILE - END WHILE
.*
.mext begin
  WHILE( logical-expression )DO      [: block-label]
      statement(s)
  END WHILE
.mext end
.np
This extension to FORTRAN 77 causes its block of code to be executed
repeatedly while the parenthesized logical expression is true.
The logical expression is evaluated before entry to the block.
If the value is false, control passes to the statement following the
.kw END WHILE
statement.
If the logical expression is true, the statements of the block are
executed.
When the
.kw END WHILE
statement is reached, the
.kw WHILE
logical expression is re-evaluated and the above program control
decisions are repeated.
.* The keyword
.* .kw DO
.* following the right parenthesis is optional.
An optional block label may be specified (see the
.kw CYCLE,
.kw EXIT
or
.kw QUIT
statement for more information).
An example follows:
.keep 10
.exam begin
      WHILE( J .GT. 0 )DO
          A(J) = B(I + J)
          J = J - 1
      END WHILE
.exam end
.np
If variable
.id J
is zero or negative when the
.kw WHILE
statement is executed, the
.kw WHILE
block of code will be by-passed and the statement following the
.kw END WHILE
statement will be executed.
.np
If variable
.id J
is greater than zero when the
.kw WHILE
statement is executed, the
.kw WHILE
block will be executed repeatedly until
.id J
becomes equal to zero.
The effect of this loop will be to assign values to elements of array
.id A
from array
.id B,
starting with the element of
.id A
corresponding to the initial value of variable
.id J
and working backwards down the array to element 1.
.*
.keep 10
.section WHILE - Executable-statement
.*
.mext begin
  WHILE( logical-expression )stmt
.mext end
.synote 5
.mnote stmt
is an executable statement.
Only certain executable statements are are allowed.
See the section entitled :HDREF refid='stmtcls'. in the chapter
entitled :HDREF refid='fstats' page=no. for a list of allowable
statements.
.endnote
.np
This control statement is another form of the WHILE construct.
.keep 5
.exam begin
      WHILE( I .GT. 0 )EXECUTE A
.exam end
.np
When this statement is executed, if the logical expression is not
true, control passes to the next statement.
If the expression is true, REMOTE-block
.id A
(assumed to be defined elsewhere in the program unit) is executed, and
the logical expression is re-evaluated.
This is repeated until the logical expression, when evaluated, is
false; control then passes to the next statement.
.*
.keep 10
.section UNTIL
.*
.mext begin
  LOOP    [: block-label]
      statement(s)
  UNTIL( logical-expression )
.mext end
.pc
or
.mext begin
  WHILE( logical-expression )DO      [: block-label]
      statement(s)
  UNTIL( logical-expression )
.mext end
.np
The
.kw UNTIL
statement, an extension to FORTRAN 77, may be combined with either a
.kw LOOP
or
.kw WHILE
statement by replacing the
.kw END LOOP
or
.kw END WHILE
statement.
It provides a way of specifying a condition to be tested at the end of
each iteration of a loop, which will determine whether or not the loop
is repeated.
After all of the statements in the block have been executed, the
logical expression in the
.kw UNTIL
statement is evaluated.
If the result of the condition is false, the loop is repeated;
otherwise, control passes to the statement following the
.kw UNTIL
statement.
.np
In the following example, the statements between the
.kw LOOP
and the
.kw UNTIL
statements are executed until the value of variable
.id X
is greater than 10.0.
.keep 10
.exam begin
      X = 1.0
      LOOP
          PRINT *, X, SQRT( X )
          X = X + 1.0
      UNTIL( X .GT. 10.0 )
.exam end
.*
.keep 17
.section SELECT - END SELECT
.*
.mext begin
  SELECT [CASE] (e) [FROM]  [: block-label]
  CASE ( case-list )
      statement (s)
  CASE ( case-list )
      statement (s)
      .
      .
      .
  CASE DEFAULT
      statement(s)
  END SELECT
.mext end
.synote 8
.mnote case-list
is a list of one or more
.us cases
separated by commas.
A
.us case
is either
.begpoint
.point (a)
a single integer, logical or character constant expression or
.point (b)
an integer, logical or character constant expression followed by a
colon followed by another expression or the same type.
This form of a case defines a range of values consisting of all
integers or characters greater than or equal to the value of the
expression preceding the colon and less than or equal to the value of
the expression following the colon.
.endpoint
.endnote
.np
The
.kw SELECT
construct, an extension to FORTRAN 77, is similar in concept to the
FORTRAN computed
.kw GO TO
statement.
It allows one of a number of blocks of code (case blocks) to be
selected for execution by means of an integer expression in the
.kw SELECT
statement.
.np
The
.kw SELECT
statement keywords,
.kw CASE
and
.kw FROM
.ct , are optional.
The
.kw SELECT
statement may contain a block label (see the
.kw CYCLE,
.kw EXIT
or
.kw QUIT
statements for more information).
.np
Each block must be started with a
.kw CASE
statement; however, the last block may begin with a
.kw CASE DEFAULT
statement.
The
.kw CASE DEFAULT
block is optional.
In order to retain compatibility with earlier versions of WATCOM
FORTRAN 77 compilers, the
.kw OTHERWISE
statement may be used in place of the
.kw CASE DEFAULT
statement.
The last block is ended by the
.kw END SELECT
statement.
The number of case blocks is optional, from one to many; however, it
is recommended that the SELECT construct not be used for fewer than 3
case blocks.
The conditional execution of one or two blocks of code is handled more
efficiently by the IF-THEN-ELSE construct.
.np
A particular case value or range of values must not be contained
in more than one CASE-block.
For example, the following is illegal:
.keep 10
.exam begin
* Illegal SELECT block - case value in more
* than one CASE block.
      SELECT CASE ( I - 3 )
      CASE (1,3,7:10)
          statement(s)
      CASE (5,6,8)
          statement(s)
      CASE (-3:-2+4)
          statement(s)
      END SELECT
.exam end
.pc
The second CASE-block includes 8 which is already handled by the
first CASE-block.
As well, the third CASE-block handles cases &minus.3, &minus.2, &minus.1, 0, 1, 2 but
the first CASE-block also handles case 1.
Thus the second and third CASE-ranges are in error.
.np
When the
.kw SELECT
statement case expression is evaluated as
.us i,
the case block whose range contains
.us i
is executed and control passes to the statement following the
.kw END SELECT
statement.
If no range contains
.us i,
control is transferred to the statement following the
.kw CASE DEFAULT
statement, if one is specified.
If the
.kw CASE DEFAULT
block is omitted and the case expression is out of range when the
.kw SELECT
statement is executed (that is, none of the CASE-blocks handles the
particular expression value), control is passed to the statement
following the
.kw END SELECT
statement and none of the CASE-blocks is executed.
.keep 20
.exam begin
      SELECT CASE ( I )
      CASE (1)
          Y = Y + X
          X = X * 3.2
      CASE (2)
          Z = Y**2 + X
          PRINT *, X, Y, Z
      CASE (3)
          Y = Y * 13. + X
          X = X - 0.213
      CASE (4)
          Z = X**2 + Y**2 - 3.0
          Y = Y + 1.5
          X = X * 32.0
          PRINT *, 'CASE 4', X, Y, Z
      END SELECT
.exam end
.pc
This example will execute in the manner described below for each of
the possible values of variable
.id I.
.begpoint
.point (i)
.id I
is zero or negative:
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (ii)
.id I = 1:
.br
- the value of
.id X
will be added to
.id Y
.br
-
.id X
will be multiplied by 3.2
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (iii)
.id I = 2:
.br
-
.id Z
will be assigned the value of the expression
.mono Y**2 + X
.br
- the values of
.id X, Y
and
.id Z
will be printed
.br
- control will pass to the statement after the
.kw END SELECT
statement
.point (iv)
.id I = 3:
.br
-
.id Y
will be assigned the value of the expression
.mono Y * 13. + X
.br
- 0.213 will be subtracted from
.id X
.br
- control will pass to the statement after the
.kw END SELECT
statement
.br
.point (v)
.id I = 4:
.br
-
.id Z, Y
and
.id X
will be assigned new values
.br
- the string
.mono CASE 4,
followed by the values of
.id X, Y
and
.id Z
will be printed
.br

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -