F90-Control.pdf

(296 KB) Pobierz
Fortran 90 Control Structures
Computer programming is an art form,
like the creation of poetry or music.
Donald Ervin Knuth
1
Fall 2010
918068875.002.png
LOGICAL Variables
LOGICAL Variables
z A LOGIAL variable can only hold either .TRUE.
y
or .FALSE. , and cannot hold values of any
other type.
other type.
z Use T or F for LOGICAL variable READ(*,*)
z WRITE(* *) prints T or F for TRUE
z WRITE(*,*) prints T or F for .TRUE.
and .FALSE. , respectively.
LOGICAL, PARAMETER :: Test = .TRUE.
LOGICAL :: C1, C2
C1 = .true. ! correct
C2 = 123 ! Wrong
READ(*,*) C1, C2
C2 = .false.
WRITE(*,*) C1, C2
2
918068875.003.png
Relational Operators: 1/4
z Fortran 90 has six relational operators: < , <= ,
p
,
,
> , >= , == , /= .
z Each of these six relational operators takes two
p
expressions, compares their values, and
yields .TRUE. or .FALSE.
z Thus, a < b < c is wrong, because a < b is
LOGICAL and c is REAL or INTEGER .
z COMPLEX values can only use == and /=
z LOGICAL values should use .EQV. or .NEQV.
for equal and not-equal comparison.
3
918068875.004.png
Relational Operators: 2/4
z Relational operators have lower priority than
Relational operators have lower priority than
arithmetic operators, and // .
z Thus 3 + 5 > 10 is FALSE and “a” //
z Thus, 3 + 5 > 10 is .FALSE. and a //
“b” == “ab” is .TRUE.
z Ch
z Character values are encoded. Different
standards ( e.g ., BCD, EBCDIC, ANSI) have
diff
t
l
d d
Diff
t
different encoding sequences.
t
di
z These encoding sequences may not be
compatible with each other.
4
918068875.005.png
Relational Operators: 3/4
z For maximum portability , only assume the
p y , y
following orders for letters and digits.
z Thus, “A” < “X” , ‘f’ <= “u” , and “2” <
, , ,
“7” yield .TRUE. But, we don’t know the
results of “S” < “s” and “t” >= “%” .
z However, equal and not-equal such as “S” /=
“s” and “t” == “5” are fine.
A < B < C < D < E < F < G < H < I < J < K < L < M < N
< O < P < Q < R < S < T < U < V < W < X < Y < Z
a < b < c < d < e < f < g < h < i < j < k < l < m < n
< o < p < q < r < s < t < u < v < w < x < y < z
0 < 1 < 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9
5
918068875.001.png
Zgłoś jeśli naruszono regulamin