This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: if statements with eqv/and


On Sun, Feb 11, 2007 at 11:40:40AM -0600, MILAD FATENEJAD wrote:
> Hello:
> I had a question about if statements involving .eqv. and .and..
> I noticed that the following code does not run as I would expect...
> 
> program test
>   implicit none
> 
>   logical :: boolean = .false.
>   integer :: num = 3
>   integer :: int = 2
>  
>   if(boolean .eqv. .TRUE. .AND. num == 2 ) then
>      print *, "Hello World"   
>   end if
> 
> end program test
> 
> If I run this program it prints "Hello World", however, if I change
> "boolean .eqv. .TRUE." to "int == 2" doesn't print anything.
> 
> I would like it to interpret the if as:
> 
> if( (boolean .eqn. .true.) .and. (num == 2) )
> 

Then you'll need to insert the parentheses.

Section 7.3 of the Fortran 2003 standard gives the precedence
the operators.  Without the parentheses in you original 
logical expression you have the following precedence "==",
".and.", and finally ".eqv.", so

(boolean .eqv. .TRUE. .AND. num == 2)

evaluates as (boolean .eqv. (.TRUE. .AND. (num == 2)))

-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]