Board index » delphi » Help on a simple repeat until loop

Help on a simple repeat until loop

What is wronge with a loop like this

Repeat
        Writeln('Enter width and length');
        Readln(Width, Length);
Until Width > 0 AND Length > 0;

Thanks,
Greg Harfst

 

Re:Help on a simple repeat until loop


Quote
In article <4e9llp$...@news.ais.net> Har...@starnetinc.com (Harfst) writes:
>From: Har...@starnetinc.com (Harfst)
>Subject: Help on a simple repeat until loop
>Date: 26 Jan 1996 04:35:05 GMT
>What is wronge with a loop like this
>Repeat
>        Writeln('Enter width and length');
>        Readln(Width, Length);
>Until Width > 0 AND Length > 0;

Let me guess.  It won't compiler.  Your problem is basic syntax,
specifically order of operations.

  Repeat
    Writeln('Enter width and length');
    Readln(Width, Length);
  Until (Width > 0) AND (Length > 0);

THAT shoud work.  Reason for problem.  the AND gets evaluated before >.  So
it tries to treat your conditional as:

  Width > (0 AND Length) > 0;

which obviously (IMHO) doesn't make sense.  (0 AND Length) is valid, but
something like # > # > # is never valid.  Just group each condition with
parentheses, and you shouldn't have this problem.

Quote
>Thanks,
>Greg Harfst

--
Scott F. Earnest / sc...@whiplash.res.cmu.edu | GO STEELERS!
Pascal Nut / Die-hard STEELERS Fan!           | '95-'96 NFL CHAMPIONS!  ;-)

Re:Help on a simple repeat until loop


Quote
In article <4ebrbm$...@news-f.iadfw.net> clifp...@airmail.net (CLIF PENN) writes:
>Regrading the following query:
>========
>Newsgroups: comp.lang.pascal.borland
>Subject: Help on a simple repeat until loop
>From: Har...@starnetinc.com (Harfst)
>Date: 26 Jan 1996 04:35:05 GMT
>What is wronge with a loop like this
>Repeat
>        Writeln('Enter width and length');
>        Readln(Width, Length);
>Until Width > 0 AND Length > 0;
>Thanks,
>Greg Harfst
>??????????????????????????????????
>6:13PM  1/26/96
>Greg,
>I see two things wrong with what you have, but the variable types
>are important, too.
>The terminating statement should be written:
>Until (xxxxx) AND (xxxxx);
>BUT--"Length" is a reserved word for Length(stringvar).

Length is NOT a reserved word, it's a procedure defined in the system unit.  
There's nothing wrong declaring a new variable called "length".  And you
can still access the original length procedure using the dot (".")
operator.  For example, this is perfectly valid:

program override;

const
  message : string = 'Hello!';

var
  length : word;

begin
  length := 99;
  writeln ('length := ',length); {This will output "length := 99".}
  writeln (system.length(message)); {This will output "6".}
end.

Granted, this is a questionable practice, but it IS possible.

Quote
>[snip]

--
Scott F. Earnest / sc...@whiplash.res.cmu.edu | GO STEELERS!
Pascal Nut / Die-hard STEELERS Fan!           | '95-'96 NFL CHAMPIONS!  ;-)

Re:Help on a simple repeat until loop


On 26 Jan 1996, Harfst wrote:

Quote
> What is wronge with a loop like this

> Repeat
>    Writeln('Enter width and length');
>    Readln(Width, Length);
> Until Width > 0 AND Length > 0;

"AND" has precedence over ">", so you need to use parentheses to have the
expression evaluated in the right order:

                Until (Width > 0) AND (Length > 0);

                                - Van Tinkess

Re:Help on a simple repeat until loop


Harfst <Har...@starnetinc.com> wrote about
Help on a simple repeat until loop
in article <4e9llp$...@news.ais.net> of 26 Jan 96:

Quote
> What is wronge with a loop like this

> Repeat
>    Writeln('Enter width and length');
>    Readln(Width, Length);
> Until Width > 0 AND Length > 0;

  Pascal actually evaluates this as:
        (( Width > 0 ) AND Length ) >0

  To get what you want, you have to write:
        ( Width > 0 ) AND ( Length > 0 )

Claus

------------------------------------------------------------------------
Claus Andre Faerber - cl...@faerber.muc.de - http://www.muc.de/~cfaerber
------------------------------------------------------------------------

Re:Help on a simple repeat until loop


HYa... All,

Friday January 26 1996 05:35, Harfst wrote to All:

 H> From: Har...@starnetinc.com (Harfst)
 H> Date: 26 Jan 1996 04:35:05 GMT
 H> Organization: Your Organization

 H> What is wronge with a loop like this

 H> Repeat
 H>   Writeln('Enter width and length');
 H>   Readln(Width, Length);
 H> Until Width > 0 AND Length > 0;
Put the last line in brackets because the compiler now thinks it has to AND
with 0 and Length... To get it right put:

Until (Width>0) AND (Length>0);

 H> Thanks,
 H> Greg Harfst
Your welcome

Zya nxt time.... Delta Ray

                       ###############################
                       # #############  ###########  #
                       # ### ##### ###  ###   ##### R#
                       # ### ####  ### ####   ### #  #
                       # ### ####  ### ####   ### # A#
                       # ### ####  ### ####   ### #  #
                       # ### ####  ### ####   ### # Y#
                       # ##################   ### #  #
                       ############################# #
                       # ########################### #
                       # # DELTA....@QUAZAR.IDN.NL # #
                       # # # ################### # # #
                       #                             #

... Success is one unpardonable sin against one's fellows.
--
| Standard disclaimer: The views of this user are strictly his own.

Re:Help on a simple repeat until loop


Quote
In article <4e9llp$...@news.ais.net> Har...@starnetinc.com (Harfst) writes:
>From: Har...@starnetinc.com (Harfst)
>Subject: Help on a simple repeat until loop
>Date: 26 Jan 1996 04:35:05 GMT
>What is wronge with a loop like this
>Repeat
>        Writeln('Enter width and length');
>        Readln(Width, Length);
>Until Width > 0 AND Length > 0;
>Thanks,
>Greg Harfst

Use parentheses in the "until" line.
Until (Width > 0) AND (Length > 0);

Re:Help on a simple repeat until loop


In a previous article, Har...@starnetinc.com (Harfst) says:

Quote
>What is wronge with a loop like this

>Repeat
>    Writeln('Enter width and length');
>    Readln(Width, Length);
>Until Width > 0 AND Length > 0;

You probably want the last line to read
    Until (Width = 0) and (Length = 0)

--
From: Sheldon C. Shallon        Internet: ad363.lafn.org
      Los Angeles, CA  USA

Re:Help on a simple repeat until loop


Quote
Sheldon Shallon (ad...@lafn.org) wrote:

:
: In a previous article, Har...@starnetinc.com (Harfst) says:
:
: >What is wronge with a loop like this
: >
: >Repeat
: >  Writeln('Enter width and length');
: >  Readln(Width, Length);
: >Until Width > 0 AND Length > 0;
: >
:
: You probably want the last line to read
:     Until (Width = 0) and (Length = 0)
:
        Sheldon, I believe the problem he was having had to due with the
lack of brackets: until (Width>0) and (Length>0);. My guess is he was
trying to avoid zero input values.
        Later,
                Luis

Re:Help on a simple repeat until loop


In article <1996Feb3.183942.15...@lafn.org>, ad...@lafn.org says...

Quote

>In a previous article, Har...@starnetinc.com (Harfst) says:

>>What is wronge with a loop like this

>>Repeat
>>       Writeln('Enter width and length');
>>       Readln(Width, Length);
>>Until Width > 0 AND Length > 0;

>You probably want the last line to read
>    Until (Width = 0) and (Length = 0)

>--
>From: Sheldon C. Shallon        Internet: ad363.lafn.org
>      Los Angeles, CA  USA

The last line needs to have brackets enclosing each seperate comparison:

     Until (Width>0) and (Length >0);

Chris.

Other Threads