next up previous contents
Next: Standard functions Up: A short summary of Previous: Data types, variables and   Contents


The order in which expressions are evaluated

The following table gives a comparison between operators in Pascal and FORTRAN.


  Pascal FORTRAN
arithmetic operators    
- raising to a power   **
- multiplication * *
- division / /
- division of integers div, mod  
- addition + +
- subtraction - -
relational operators    
- smaller $<$ .lt.
- greater or equal $<=$ .le.
- greater $>$ .gt.
- greater or equal $>=$ .ge.
- equal = .eq.
- not equal $<>$ .ne.
logical operators    
- not not .not.
- and and .and.
- or or .or.



The order in which expressions are evaluated is as follows:
  1. **
  2. * and /
  3. + and -
  4. .lt., .le., .eq., .ne., .ge. and .gt.
  5. .not.
  6. .and.
  7. .or.
Within each level evaluation is performed from left to right.
The order of evaluation can be changed by using semicolons.
Example:
      program order
      implicit none
      integer n, nmax
      logical conv, result
      conv = .true.
      n = 5
      nmax = 20
      result = .not. conv .and. 2*n .lt. nmax
      print *, 'result = ', result
      end
If we execute the program above the expression is evaluated as follows:
  1. 2*n which gives r1 = 10
  2. r1 .lt. nmax, which gives r2 = .true.
  3. .not. conv, which gives r3 = .false.
  4. r3 .and. r2, which gives: .false.
The program will print: result = .false.
next up previous contents
Next: Standard functions Up: A short summary of Previous: Data types, variables and   Contents
Mathieu Pourquie 2001-02-28