FORTRAN Constants and Variables
- Credits for Lecture and Authoring
- Computer Language
- Contents of Fortran Programming
- FORTRAN Characters
- FORTRAN Chars Defined
- FORTRAN Numbers
- Integers
- Reals
- FORTRAN Variables
- FORTRAN Variable Rules
- FORTRAN Expression
- Ex: Expressions
- FORTRAN Hierarchy
- FORTRAN Hierarchy Def'n
- FORTRAN Program
- Assignment Statement (cont'd)
- Ending the Program
Lecture written by: Prof Martha Selby
Authored for presentation by:
Mark Sobek
Revised by: John Even
Converted to HTML by: William Hart
A set of characters and rules governing the use of the characters for
communication with a computer.
Examples:
- FORTRAN (Formula Translation)
- C
- COBOL
- Etc.
A FORTRAN program consits of a series of:
- FORTRAN statements (Instructions) Utilizing various
- FORTRAN expressions formed by various combinations of
- FORTRAN constants and
- FORTRAN variables constructed from a set of
- FORTRAN characters
Characters are available to the program writer to fomulate:
- Numbers
- Variables
- Expressions
- All uppercase and lowercase letters (A-Z, a-z)
- The numerals 0 through 9
- The following special characters:
= Equal sign , Comma : Colon
+ Plus sign . Period < Left angle bracket
- Minus sign ' Apostrophe > Right angle bracket
* Asterisk " Quotation Mark % Percent sign
/ Slash $ Dollar sign & Ampersand
( Left Parenthesis _ Underscore < TAB >Tab key
) Right Parenthesis ! Exclamation Point < Space > Space Char
FORTRAN numbers can be either
- Integer
- Real
- Integer
Contains no decimal point.
Contains no fractional values
Generally used as counters in looping
processes.
Computer truncates and reduces results to
next lower integer in an integer division (4/3=1, 17/5=3)
- Real
Contains a decimal point
May be expressed in either of two forms
Without an exponent (eg. 123.4)
With an exponent (eg 0.1234E 03)
FORTRAN variables are quantities that are given names & whose values
vary during program execution.
Five types of variables exist:
- Integer variables
- Real variables
- Character (discussed later)
- Logical (discussed later)
- Complex (not covered in this course)
The term "integer" and "real" carry the same meaning for both FORTRAN
variables and FORTRAN numbers.
- The first character of a FORTRAN variable must be a
letter.
- Subsequent characters may be any combination of letters and
digits. Special characters are not allowed.
- No more than six (6) characters may be
used in a variable name.
- Blank spaces are not counted.
- Unless explicitly declared otherwise, an integer
variable must begin with I, J, K, L, M, or N
and a real variable must begin with one of the remaining
alphabetic characters.
- Only one name may be used for each
FORTRAN variable.
- Before a variable name can be used in computation, it must
be assigned a value!
- FORTRAN vocabulary words are not allowed (READ, WRITE,
STOP, etc.)
A FORTRAN expression is any mathematical relationship
of FORTRAN constants and variables .
The order in which a FORTRAN program performs mathematical operations.
- Clear parentheses, scanning from left to right, clearing
from left to right.
- Exponentiation, scanning from left to right, exponentiating
from right to left. Hence Y=A**B**C is the same as
Y=A**(B**C).
- Multiplication and/or division left to right.
- Addition and/or subtraction and/or negation left to right.
A FORTRAN program is made up of a series of instructions called
statements.
Arithmetic assignment statement:
A particular type of statement that assignes the results of a numerical
computation to a named FORTRAN variable.
Example:
Y=A*B**2
Upon encountering this statement, the computer
evaulates the FORTRAN expression ,
assigns the value to the
variable and then stores Y in a predefined
location in the computer's memory.
Following the last executable FORTRAN statement in a computer program, a
"STOP" statement may be included. This terminates the execution of the
program.
The last statement in a computer program must be an "END" statement.
This terminates the compilation. If no STOP statement is included, one
will be assumed when the END statement is reached.