The Queen's University of Belfast
Parallel Computer Centre

[Next] [Previous] [Top]

Logical & comparison expressions


Logical & comparison expressions

Topics

Relational operators

Form

object1 rel_operator oblect2

Example

LOGICAL :: test, ntest(5)

INTEGER :: age, my_age, your_age(5)

CHARACTER(len=5) :: name

...

test = 5 < 6 !true

test = 5 <= 6 !true

test = 5 > 6 !false

test = 5 => 6 !false

test = 5 == 6 !false

test = 5 /= 6 !true

...

ntest = your_age > 34

test = your_age(1) /= my_age

test = name == `Smith'

test = (age*3) /= your_age(3)

The objects compared may be variables, constants, array elements (numeric or character) or expressions.

Logical expressions

Form

expression1 logical expression2

Example

LOGICAL :: test, part1, part2

...

part1 = 5*3 > 12 !true

part2 = 6*2 < 12 !false

...

test = part1 .AND. part2 !false

test = part1 .OR. part2 !true

test = .NOT. part 1 !false

test = .NOT. part2 !true

test = part1 .EQV. part2 !false

test = part1 .NEQV. part2 !true

...

Character comparison

Certain rules are applied when comparing characters or strings (is `A' greater than `B'?)

The collating sequence

test = `Alexis' > `Alex'

Portability issues

LLT(str1, str2) !str1 < str2

LLE(str1, str2) !str1 <= str2

LGE(str1, str2) !str1 > str2

LGT(str1, str2) !str1 >= str2

These should be used where ever possible.


[Next] [Previous] [Top]
All documents are the responsibility of, and copyright, © their authors and do not represent the views of The Parallel Computer Centre, nor of The Queen's University of Belfast.
Maintained by Alan Rea, email A.Rea@qub.ac.uk
Generated with CERN WebMaker