Recent

Author Topic: Pascal IF Boolean1 AND Boolean2 THEN DoWhatever?  (Read 3425 times)

Elmug

  • Hero Member
  • *****
  • Posts: 849
Pascal IF Boolean1 AND Boolean2 THEN DoWhatever?
« on: July 20, 2011, 07:04:38 am »
I thought we had in Pascal, in the IF-THEN category, that could handle something like this:

If Condition1 AND Condition2 THEN DoWhatever; but looks like I am confused. ...Where Condition1 can be an expression and Condition2 can be a boolean or mixes of conditions or of same kind.

Can anyone please clarify? Or what is a good simple equivalent?

Thanks.
« Last Edit: July 20, 2011, 07:11:44 am by Elmug »

Kyjan

  • New Member
  • *
  • Posts: 41
Re: Pascal IF Boolean1 AND Boolean2 THEN DoWhatever?
« Reply #1 on: July 20, 2011, 08:13:56 am »
Hi,

as far as I know you can do it the following way:

if (i <2) and (not b) then...

b is boolean.

HTH
Kyjan

Zoran

  • Hero Member
  • *****
  • Posts: 1988
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Pascal IF Boolean1 AND Boolean2 THEN DoWhatever?
« Reply #2 on: July 20, 2011, 08:27:37 am »
The operator precedence in Pascal may differ from what one intuitively expect. Therefore, always use parenthesis to be sure when mixing boolean and relational operators (just like Kyjan did in the example above).

Do not use:
Code: [Select]
if m = n or b then ...
But:
Code: [Select]
if (m = n) or b then ...
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

 

TinyPortal © 2005-2018