Whats the command to end a program? 
Author Message
 Whats the command to end a program?

Hi,

[see subject]

The command to end a program ist Halt (with an optional parameter which
will be the program's return code and may be restricted to a byte by
the operating system (is that true?)).

Quote:
> writeln ('Are you sure you want to Quit? [Y/N]');
>         d := readkey;
>            CASE d OF
>            'y': writeln ('Exit');
>            'n': MENU;

> This is in procedure quit;

> When the user presses 'Y' I want the program to finish

You should have taken the responses to your previous question more
serious. Compared to this program, "spaghetti code" is nothing. A
well-structured menu structure would look like this:

   function askquit : Boolean
   begin
    ...
   end;

   var wantquit : Boolean;
       choice : Char;  { for example }

   begin
      wantquit := False;
      repeat
         print menu
         read choice
         case choice of
            'a' : ...;  { possibly procedure calls }
            'b' : ...;
            'q' : wantquit := askquit;
         end;
      until wantquit;
   end.

Note that this is partly pseudo-code.

 - Sebastian



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
writeln ('Are you sure you want to Quit? [Y/N]');
        d := readkey;
           CASE d OF
           'y': writeln ('Exit');
           'n': MENU;

This is in procedure quit;

When the user presses 'Y' I want the program to finish

Thanks once again..

BHD



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
<snip>

Halt( exitcode )

:-)



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
Im sorry this didn't make any sense to me. Bear in mind im very new to
Pascal and doing it for school.
Quote:
> You should have taken the responses to your previous question more
> serious. Compared to this program, "spaghetti code" is nothing. A
> well-structured menu structure would look like this:

>    function askquit : Boolean
>    begin
>     ...
>    end;

>    var wantquit : Boolean;
>        choice : Char;  { for example }

>    begin
>       wantquit := False;
>       repeat
>          print menu
>          read choice
>          case choice of
>             'a' : ...;  { possibly procedure calls }
>             'b' : ...;
>             'q' : wantquit := askquit;
>          end;
>       until wantquit;
>    end.

> Note that this is partly pseudo-code.

>  - Sebastian



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
Also whats the 'byte' command?
Var XX : byte??


Quote:
> Hi,


> [see subject]

> The command to end a program ist Halt (with an optional parameter which
> will be the program's return code and may be restricted to a byte by
> the operating system (is that true?)).

> > writeln ('Are you sure you want to Quit? [Y/N]');
> >         d := readkey;
> >            CASE d OF
> >            'y': writeln ('Exit');
> >            'n': MENU;

> > This is in procedure quit;

> > When the user presses 'Y' I want the program to finish

> You should have taken the responses to your previous question more
> serious. Compared to this program, "spaghetti code" is nothing. A
> well-structured menu structure would look like this:

>    function askquit : Boolean
>    begin
>     ...
>    end;

>    var wantquit : Boolean;
>        choice : Char;  { for example }

>    begin
>       wantquit := False;
>       repeat
>          print menu
>          read choice
>          case choice of
>             'a' : ...;  { possibly procedure calls }
>             'b' : ...;
>             'q' : wantquit := askquit;
>          end;
>       until wantquit;
>    end.

> Note that this is partly pseudo-code.

>  - Sebastian



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
Hi,

Quote:

> Also whats the 'byte' command?
> Var XX : byte??

It is a numerical data type, 8 bit unsigned integer. You can imagine
it to be declared as:

   type Byte = 0..255;

Your line would declare XX to be of type Byte. Example:

   program byteme;

   {$R-}

   var b : Byte;

   begin
      b := 165;
      Writeln(b);
      b := b + 124;
      Writeln(b);
   end.

This will produce the following output:

   165
   33

If you change {$R-} to {$R+}, range checking is activated, and
instead of the overflow, you'll get a runtime error.

HTH,

 - Sebastian



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?

Quote:
> Im sorry this didn't make any sense to me. Bear in mind im very new to
> pascal and doing it for school.

   It's somewhat surprising that your school class hasn't discussed some
of these fundamental programming concepts, particularly in relation to
Pascal.  8<{{
   In any event, you should know that Pascal doesn't _need_ any statement
to terminate a program: it's what naturally occurs when the code logic
has nothing more to do...and falls into the source code's "end."
statement.  That's how most Pascal programs "terminate", and it's the
natural way to design most programs.
   There is a statement in TP/BP which supports _premature/abnormal_
termination - the Halt statement.  Again, it's not normal to use it, but
it exists for exceptional logic situations.
   The normal Pascal source template should, imho, look much like this:
program program_name;
Const Limit    = 10;                          { global constants }
Type  Arr_Type = array[1..Limit] of integer;  { global Type }
Var   My_Data  : Arr_Type;                    { global data array }
      I        : integer;
procedure P1(PInt : integer);
begin
  writeln ('In P1, the data value is: ',PInt)
end;
function My_Square (N : integer): integer;
begin
  MySquare := N*N
end;
begin             { Main Line }
  I := 0;
  repeat
    I := I+1;
    P1(My_Square(I))
  until I >= Limit;
  writeln ('End of program.')
end.
   In the above program example, a main line loop calls 2 subprograms (a
procedure and a function) as it iterates a finite number of times.  After
the loop terminates, a "verification statement" is issued, showing that
the loop terminated, and the logic "falls through" to the "end.".  If
this code compiles and executes (I didn't test it), all will operate as
expected - if one knows what the Pascal statements do - and no explicit
"termination statement" is needed.
Quote:

> > You should have taken the responses to your previous question more
> > serious. Compared to this program, "spaghetti code" is nothing. A
> > well-structured menu structure would look like this:
> >    function askquit : Boolean
> >    begin
> >     ...
> >    end;

> >    var wantquit : Boolean;
> >        choice : Char;  { for example }

> >    begin
> >       wantquit := False;
> >       repeat
> >          print menu
> >          read choice
> >          case choice of
> >             'a' : ...;  { possibly procedure calls }
> >             'b' : ...;
> >             'q' : wantquit := askquit;
> >          end;
> >       until wantquit;
> >    end.



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?

Quote:
> Also whats the 'byte' command?
> Var XX : byte??

   You've admitted that you are learning, so I'll give you the benefit of
your inexperience.
   First, you should learn/accept that a programming language such as
Pascal doesn't have "commands" - it has statements, procedures,
functions, declarations, and other language elements.  An operating
system or command interpreter has "commands", but to ascribe that verb to
a programming language's components is wrong and confusing (to you).  You
really should understand the distinction and apply it in your future
postings.
   Second, "byte" is one of the TP/BP standard data types.  It doesn't
_do_ anything, insofar as logic or functionality; it merely states that
the declaration of XX has certain intended abilities and uses...versus
other Pascal data types.
   This is a key element of Pascal's "strong data typing", with which the
language enforces that certain things can be done to and with "byte
data", and _only_ the byte's designed purposes can be used on XX.  As you
get further into the understanding of Pascal, you will learn these rules,
because if you violate or misuse them, your program won't compile (or
execute).  For example, you can perform certain arithmetic calculations
on bytes, but you can't do such things to string data or structures.  
Certain languages don't enforce such control of data types and
operations, and programmers can make errors which are hard to find and
fix with such languages.
   Pascal doesn't have such flaws, which is why it's such a good teaching
vehicle.


Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?

Quote:
>When the user presses 'Y' I want the program to finish

sorry but I couldn't resist here.

Procedure Finish;
Begin
        asm
          int 19h
        end;
End;

Mike McWhinney
elja, Inc.

Quote:

>Thanks once again..

>BHD



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
What does that so?


Quote:
> >When the user presses 'Y' I want the program to finish

> sorry but I couldn't resist here.

> Procedure Finish;
> Begin
> asm
>          int 19h
> end;
> End;

> Mike McWhinney
> elja, Inc.

> >Thanks once again..

> >BHD



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?


Quote:
> >When the user presses 'Y' I want the program to finish

> sorry but I couldn't resist here.

> Procedure Finish;
> Begin
> asm
>          int 19h
> end;
> End;

You can write this procedure in shorter format too:

 Procedure Finish;assembler;
 asm
          int 19h
 end;

Or you can just use inline: Inline($CD,$19);

Quote:
> Mike McWhinney
> elja, Inc.

> >Thanks once again..

> >BHD



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?

Quote:

>What does that so?

Most likely it crashes the computer. There is some urban legend that int
19h has something to do with rebooting the computer. In fact it is just
a bootstrap loader for internal use of the system.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
Or you could just:

WriteLn('please shutoff coputer');

Quote:



> > >When the user presses 'Y' I want the program to finish

> > sorry but I couldn't resist here.

> > Procedure Finish;
> > Begin
> > asm
> >          int 19h
> > end;
> > End;

> You can write this procedure in shorter format too:

>  Procedure Finish;assembler;
>  asm
>           int 19h
>  end;

> Or you can just use inline: Inline($CD,$19);

> > Mike McWhinney
> > elja, Inc.

> > >Thanks once again..

> > >BHD



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?
The command to end a program is Halt;
You can also write a procedure called Halt; (override TP's own proc)

Procedure Halt; Assembler;
Asm
  Move Ax,4Ch
  Int 21h
End;



Quote:
> writeln ('Are you sure you want to Quit? [Y/N]');
>         d := readkey;
>            CASE d OF
>            'y': writeln ('Exit');
>            'n': MENU;

> This is in procedure quit;

> When the user presses 'Y' I want the program to finish

> Thanks once again..

> BHD



Wed, 18 Jun 1902 08:00:00 GMT  
 Whats the command to end a program?

Quote:

>The command to end a program is Halt;
>You can also write a procedure called Halt; (override TP's own proc)

>Procedure Halt; Assembler;
>Asm
>  Move Ax,4Ch
>  Int 21h
>End;

Very bad idea.  I mean extremely bad idea. That should be renamed as
Crash as it does no clearing that is needed to exit TP program.

Osmo



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. How run a program.exe at the end of a pascal program

2. Execute DOS-command/program from a program.

3. Execute DOS-command/program from a program.

4. Can we do programming without seeing the end u

5. Exception at program end

6. How to end a program

7. free idsoftware front-end program in pascal--need help - idgames.pas [1/1]

8. Ending a program

9. free idsoftware front-end program in pascal--need help - idgames.pas [1/1]

10. End program & start another

11. Can we do programming without seeing the end u

12. Ending a program in a procedure

 

 
Powered by phpBB® Forum Software