Board index » delphi » if, or?

if, or?

Can't you write like this in Pascal:

if x=1 or y=1 then begin
code....
end;

if x=1 and y=1 then begin
code...
end;

You can do that in C || and even in Qbasic?! I think it should work! :)
But does it?
/Tobz

 

Re:if, or?


Quote
Tobias Andersson wrote:

> Can't you write like this in Pascal:

> if x=1 or y=1 then begin

> You can do that in C || and even in Qbasic?! I think it should work! :)
> But does it?
> /Tobz

Try:

if (x=1) or (y=1) then begin

it should work...

/Niklas Bj?rnest?l <s...@linux.nu>

Re:if, or?


On Mon, 24 Aug 1998 13:32:19 GMT, Tobias Andersson

Quote
<Tobias.Anders...@mbox3.swipnet.se> wrote:
>Can't you write like this in Pascal:

>if x=1 or y=1 then begin
>code....
>end;

>if x=1 and y=1 then begin
>code...
>end;

You need brackets:
if (x=1) or (y=1) then begin
if (x=1) and (y=1) then begin

- Ulli -
===
"On no account allow a Vogon to read poetry at you!"

Ulli Conrad
ucon...@gmx.net
http://www.gwdg.de/~uconrad1
Public PGP-Key at http://www.gwdg.de/~uconrad1/upgpkey.asc

Re:if, or?


In article <35E16C06.94C6A...@mbox3.swipnet.se>, Tobias.Anders...@mbox3.swipnet.se says...
;>
;>Can't you write like this in Pascal:
;>
;>if x=1 or y=1 then begin
;>code....
;>end;
;>
;>if x=1 and y=1 then begin
;>code...
;>end;
;>
;>You can do that in C || and even in Qbasic?! I think it should work! :)
;>But does it?
;>/Tobz
;>
;>
;>

if (x=1) or (y=1) then begin
code....
end;

if (x=1) and (y=1) then begin
code....
end;

AND and OR have higher precidence than = in Pascal. It would be
unwise to expect all of your languages to have a similar precidence.
They are completely arbitrary.

                                       [sam]

Re:if, or?


Quote
Scott A. Moore wrote:
> if (x=1) or (y=1) then begin
> code....
> end;

> if (x=1) and (y=1) then begin
> code....
> end;

> AND and OR have higher precidence than = in Pascal. It would be
> unwise to expect all of your languages to have a similar precidence.
> They are completely arbitrary.

There's also the issue that the Pascal syntax says that AND and OR go
between booleans.
Without parentheses, one could parse "if x = 1 or y = 1" as "if x = (1
or (y = 1))", where
you have an integer (1) as one of the arguments of OR (or AND).  This
violates Pascal's
Strong Typing rules.

Bob Schor
Pascal Enthusiast

Re:if, or?


In article <35E16C06.94C6A...@mbox3.swipnet.se>,
  Tobias Andersson <Tobias.Anders...@mbox3.swipnet.se> wrote:

Quote
> Can't you write like this in Pascal:

> if x=1 or y=1 then begin
> code....
> end;

> if x=1 and y=1 then begin
> code...
> end;

> You can do that in C || and even in Qbasic?! I think it should work! :)
> But does it?

The first question to ask yourself is "what do I want to do".  You can write
those expressions, but without knowing exactly what the precedences are you
will rapidly become confused.  So add enough parentheses to make it perfectly
clear to yourself, and to whoever else reads your code.  They won't make
anything run slower. Also use spaces, e.g. "IF (x = 1) AND (y = 1) THEN"

Hint - AND has a different precedence than OR in Pascal

--
    Chuck Falconer (Charles_Falco...@NOSPAMapsnet.com)

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Other Threads