Home | Notes | Languages | Programs | Homework |
Re: or |
Stephen Edwards (edwards@CS.VT.EDU)
Wed, 19 Sep 2001 21:02:17 -0400
Message-ID: <3BA94019.1BCFEC6F@cs.vt.edu> Date: Wed, 19 Sep 2001 21:02:17 -0400 From: Stephen Edwards <edwards@CS.VT.EDU> Subject: Re: or
Kirk Spaziani wrote:
>
> or is simply or
>
> if ( (blah) or (blah) ) then begin ... end
^----^ ^----^
This is correct. Note that the parentheses are not required in
Pascal (unlike in C and Java).
That said, though, another important point that might cause some people
trouble is that Pascal does not use the precedence levels one normally
expects of modern languages. In particular, the logical operators "and"
and "or" have *higher* precedence than relational operators, such as = or
<=. That means if you write something like this, you'll be surprised:
if a = 10 and b = 25 then
You'll get compiler errors because you cannot "or" 10 and b, and because
the expression does not parse correctly.
The result is that in Pascal, it is usually safest to always use parentheses
when and'ing or or'ing simpler expressions in conditions.
-- Steve
-- Stephen Edwards 604 McBryde Hall Dept. of Computer Science e-mail : edwards@cs.vt.edu U.S. mail: Virginia Tech (VPI&SU) office phone: (540)-231-5723 Blacksburg, VA 24061-0106 -------------------------------------------------------------------------------
Home | Notes | Languages | Programs | Homework |