loop??PLS HELP! 
Author Message
 loop??PLS HELP!

Hi...
I've been trying to figure out a loop that at the end of the program says:
If you want to go to begining of the program, press YES...
how do I do this?
I have the program that is called OHM. It calculates
some numbers.

PROGRAM OHM;
variables;
CASE OF
1
2
3
END.
What would be the proper code to put and where on the structure of what I
put here that would reinitiate the program..
If you want to see the code I wrote, please let me know.



Sun, 06 Nov 2005 05:45:07 GMT  
 loop??PLS HELP!


Quote:
>What would be the proper code to put and where on the structure of what I
>put here that would reinitiate the program..

Normally a WHILE statement or a REPEAT/UNTIL pair.


Sun, 06 Nov 2005 09:32:14 GMT  
 loop??PLS HELP!


Quote:
>Hi...
>I've been trying to figure out a loop that at the end of the program says:
>If you want to go to begining of the program, press YES...
>how do I do this?
>I have the program that is called OHM. It calculates
>some numbers.

>PROGRAM OHM;
>variables;
>CASE OF
>1
>2
>3
>END.
>What would be the proper code to put and where on the structure of what I
>put here that would reinitiate the program..
>If you want to see the code I wrote, please let me know.

{Since you are using a selection menu followed by a case statement,
why not just make the last selection 'Quit', such as: }

Program LoopTermination;
VAR choice:Integer;

Procedure Menu(VAR select:Integer);
Begin
     Writeln; Writeln('MENU':20);
     Writeln('1. Calculation One');
     Writeln('2. Calculation Two');
     Writeln('3. Calculation Three');
     Writeln('4. QUIT');
    Writeln;
    Repeat
          Write('Choose a number (1..4): ');
          Readln(select);
    Until select in [1..4];
End;

Procedure DummyOp(select:Integer);
Begin
     Writeln('You chose calculaion ', select);     Writeln;
End;

BEGIN
     Repeat
           Menu(choice);
           Case(choice) of
              1: DummyOp(choice);
              2: DummyOp(choice);
              3: DummyOp(choice);
           End;
     Until choice = 4;
END.



Tue, 08 Nov 2005 05:47:09 GMT  
 loop??PLS HELP!



Quote:


> >Hi...
> >I've been trying to figure out a loop that at the end of the program
says:
> >If you want to go to begining of the program, press YES...
> >how do I do this?
> >I have the program that is called OHM. It calculates
> >some numbers.

> >PROGRAM OHM;
> >variables;
> >CASE OF
> >1
> >2
> >3
> >END.
> >What would be the proper code to put and where on the structure of
what I
> >put here that would reinitiate the program..
> >If you want to see the code I wrote, please let me know.

> {Since you are using a selection menu followed by a case statement,
> why not just make the last selection 'Quit', such as: }

> Program LoopTermination;
> VAR choice:Integer;

> Procedure Menu(VAR select:Integer);
> Begin
>      Writeln; Writeln('MENU':20);
>      Writeln('1. Calculation One');
>      Writeln('2. Calculation Two');
>      Writeln('3. Calculation Three');
>      Writeln('4. QUIT');
>     Writeln;
>     Repeat
>           Write('Choose a number (1..4): ');
>           Readln(select);
>     Until select in [1..4];
> End;

> Procedure DummyOp(select:Integer);
> Begin
>      Writeln('You chose calculaion ', select);     Writeln;
> End;

> BEGIN
>      Repeat
>            Menu(choice);
>            Case(choice) of
>               1: DummyOp(choice);
>               2: DummyOp(choice);
>               3: DummyOp(choice);
>            End;
>      Until choice = 4;
> END.

Ever wrote a menu driven program before?
This way you'll lose track of the options.
Better store the entire menu in one procedure.

e.g.

procedure mymenu;
begin
  repeat
     clrscr;
     writeln('A= do this');
     writeln('B= do that');
     writeln('ESC= exit');
     case upcase(readkey) of
        'A':dothis;
        'B':dothat;
        #27:exit;
        else write(#7);  {beep}
     end;
   until false;
end;

The procedures dothis and dothat can be menu's themselves that
take exactly the same form or they may be procedures doing the demanded
thing from the menu choise.

In general:
You should try to AVOID global variabeles. Chances are that you
accidently modify it's value in another procedure.
If you need a return variabele from a procedure, turn it into a function
instead, or use var in the headers.

--
Femme



Tue, 08 Nov 2005 07:59:23 GMT  
 loop??PLS HELP!

Quote:

> I've been trying to figure out a loop that at the end of the
> program says: If you want to go to begining of the program,
> press YES... how do I do this?
> I have the program that is called OHM. It calculates
> some numbers.

> PROGRAM OHM;
> variables;
> CASE OF
> 1
> 2
> 3
> END.
> What would be the proper code to put and where on the structure
> of what I put here that would reinitiate the program..
> If you want to see the code I wrote, please let me know.

You want some sort of while or repeat structure, dependent on
whether you want to ensure that the main code is always executed
at least once, or not.  Consider:

PROGRAM ohm(input, output);

   TYPE
      operation = (quit, opone, optwo);

   VAR
      thisop : operation;

   (* 1-------------1 *)

   FUNCTION getopt : operation;

      VAR selection : operation;

      BEGIN (* getopt *)
      (* fill in the appropriate details *)
      getopt := selection;
      END; (* getopt *)

   (* 1-------------1 *)

   BEGIN (* ohm *)
   REPEAT
      thisop := getopt;
      CASE thisop OF
quit:    (* nothing *);
opone:   (* as needed *);
optwo:   (* etc. *);
      END (* case *)
   UNTIL thisop = quit;
   END. (* ohm *)

as a starting outline.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Fri, 11 Nov 2005 10:42:48 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Start Trans - commit, pls help

2. PLS HELP - Query vs SubString

3. Reportsmith: Pls Help!

4. Delphi ODBC connection to server DB..pls help!

5. Pls HELP ME !!!!!

6. Dynamic Link List - help pls!

7. PLS HELP ME!

8. Pls HELP ME !!!!!

9. pls help! convert amount to words

10. Grabing whole win95 screen in Delphi/help pls/

11. Urgent: HELP ME PLS

12. Strang Error message: pls help!

 

 
Powered by phpBB® Forum Software