Board index » delphi » Repeat- Until (simple question)

Repeat- Until (simple question)

Quote
tr...@bc.{*word*104}nex.net (Eddie) wrote:

Eddie,

Quote
>Hi, I know this is probably a question to basic to be in here, but not even the FAQs have it :).  

  There is no such thing as a "basic" question.  This is the forum where
we can all learn.  "Basic" is relative, what is basic to you may not be
basic to someone else.  So ask away!

Quote
>I have written a program lets say with multiple
>repeats and untils within different parts of the program, here is an
>example.
>program test;
>var
>  a,b,x,y:int
>begin
>  repeat
>    read (x,y);
>    a := x+y
>    if a=x+y then
>    begin
>      repeat
>        read (b);
>     if b= y then
>        begin
>       writeln('hi')
>        end;  { if... }      {!!ES}
>      until 1=1;
>    end;  { if... }
>  until 2=2
>end.  { program Test }

  After reformatting your code (so that the begin's & end's / repeat's &
until's line up), you could see that the code you had posted was
incorrect (probably wouldn't compile).  I highly recommend using
indentation as a way to group nested procedures.  It makes error tracking
much easier.  Anyhow...  I had to add an end (indentified with !!ES) to
make your example compilable.  

Quote
>this program makes has no point to it and will just keep asking for the same
>thing, but the goal that i want(this isn't really the real program) is for
>the until for the 3rd section of the program (until 1=1) will link to the
>original repeat after the first begin.
>until and the until 2=2 will link itself to the if b=y then begin repeat.
>basicly what I want is some way link the untils and repeats to each other
>without being in the same sub program.

  I'm not sure what you mean by "linking" the untils and repeats but
both until 1=1 and until 2=2 create end-less loops which in this example
would never break out of.  To break out of one of these loops you would
need to add a break call.  To wit:

Quote
>      repeat
>        read (b);
>     if b= y then
>        begin
>       writeln('hi')
>          break;             {!!ES}
>        end;  { if... }      {!!ES}
>      until 1=1;

Was that the answer you were looking for?  If not drop me an e-mail with
a more descriptive example and I'ld be happy to look at it.

Quote
>Thanks for any help, and I am sorry
>if I annoy any of you for such a basic question, I apologise for any
>inconveniance.

Never an inconvenience.

Good Luck,

-Ed Salgado
 Eminent Domain Software

 

Re:Repeat- Until (simple question)


Hi, I know this is probably a question to basic to be in here, but not even
the FAQs have it :).  I have written a program lets say with multiple
repeats and untils within different parts of the program, here is an
example.

program test;

var
a,b,x,y:int
begin
repeat
read (x,y);
a := x+y
if a=x+y then
        begin
        repeat
        read (b);
        if b= y then
                begin
                writeln('hi')
                until 1=1
                end;
        end;
until 2=2
end.

this program makes has no point to it and will just keep asking for the same
thing, but the goal that i want(this isn't really the real program) is for
the until for the 3rd section of the program (until 1=1) will link to the
original repeat after the first begin.
until and the until 2=2 will link itself to the if b=y then begin repeat.
basicly what I want is some way link the untils and repeats to eachother
without being in the same sub program.  Thanks for any help, and I am sorry
if I annoy any of you for such a basic question, I apologise for any
inconveniance.

                                                Eddie

Re:Repeat- Until (simple question)


Quote
On Thu, 19 Oct 1995, Eddie wrote:
> Hi, I know this is probably a question to basic to be in here, but not even
> the FAQs have it :).  I have written a program lets say with multiple
> repeats and untils within different parts of the program, here is an
> example.

> program test;

> var
>   a,b,x,y:int
> begin
>   repeat
>     read (x,y);
>     a := x+y
>     if a=x+y then
>      begin
>       repeat
>         read (b);
>         if b= y then
>          begin
>           writeln('hi')
>       until 1=1
>      end;
>    end;
> until 2=2
> end.

Uh, I was trying to make your source readable, but if you'll notice,
you've got something weird going on with your begins, ends, and repeats...

Quote
> this program makes has no point to it and will just keep asking for the same
> thing, but the goal that i want(this isn't really the real program) is for

If it were correct, it would only go through the loop once.

Quote
> the until for the 3rd section of the program (until 1=1) will link to the
> original repeat after the first begin.
> until and the until 2=2 will link itself to the if b=y then begin repeat.
> basicly what I want is some way link the untils and repeats to eachother
> without being in the same sub program.  Thanks for any help, and I am sorry
> if I annoy any of you for such a basic question, I apologise for any
> inconveniance.

Uhhh... I think you're going about your problem completely wrong.  Try
adding in structured programming into the scheme of it; in fact, it may
be therapeutic to make a flowchart first.  But it sounds like you're
trying to do stuff which would involve GOTOs, which is why I claim that
you're approaching the problem wrong.

Either that or you want to enter the Obfuscated Pascal contest. :)

    ________________________________________________________________________
   / Joshua Shagam                    /    (Quantum Porcupine / Versatile) /
  / mailto:JSha...@nmsu.edu          /       http://web.nmsu.edu/~jshagam /
 / phone://1.505.645.3856/~joshua   /  for the Quantum Porcupine Archive /
/__________________________________/____________________________________/
Q: How many hoards would the monguls board if the mongul hordes got bored?
A: The monguls would board all the hoards if the hordes got really bored.

Re:Repeat- Until (simple question)


In article <DGo6FG....@news2.new-york.net>,

Quote
Eddie <tr...@bc.{*word*104}nex.net> wrote:
>this program makes has no point to it and will just keep asking for the same
>thing, but the goal that i want(this isn't really the real program) is for
>the until for the 3rd section of the program (until 1=1) will link to the
>original repeat after the first begin.
>until and the until 2=2 will link itself to the if b=y then begin repeat.
>basicly what I want is some way link the untils and repeats to eachother
>without being in the same sub program.  Thanks for any help, and I am sorry
>if I annoy any of you for such a basic question, I apologise for any
>inconveniance.

Not sure *what* you're asking here:  "How can I make a bunch of independent
repeat ... until blocks 'stop' at the same time?"

If that *is* what you mean, you could use a global variable, initialized
to false.  When you set it true, the until tests all stop repeating.

--

http://www.armory.com/~jon               Personal Pages
http://www.armory.com/~jon/pubs             Programming Publications
http://www.armory.com/~jon/hs         Home School Resource List

Re:Repeat- Until (simple question)


Quote
In article <46c2sq$...@news.scruz.net> j...@armory.com (Jon Shemitz) writes:
>In article <DGo6FG....@news2.new-york.net>,
>Eddie <tr...@bc.{*word*104}nex.net> wrote:
>Not sure *what* you're asking here:  "How can I make a bunch of independent
>repeat ... until blocks 'stop' at the same time?"
>If that *is* what you mean, you could use a global variable, initialized
>to false.  When you set it true, the until tests all stop repeating.

Another trick is to put all the repeat blocks in a procedure, and EXIT at the
appropriate moment.
--
John Stockton : mailto:J...@dclf.npl.co.uk from off-site.  MIME.  WP.
 National Physical Laboratory, Teddington, Middlesex, TW11 0LW, UK
  Direct Phone +44 181-943 6087, Nearby Fax +44 181-943 7138  
   Postings out, Email in/out are fast.  Offshore news takes 0..10+
    days to arrive; please mail me a copy of non-UK followups!  
     Regret system puts unzoned (UK civil) time on messages.

Other Threads