You are on page 1of 7

Common Pascal Procedures & Functions

2. Program control and display Procedures & Functions Function Description ClrScr* Clears the screen and returns the cursor to the upper left corner. procedure ClrScr; Dec Decrements a variable. procedure Dec(var X[ ; N: Longint]); DoneWinCrt** Closes the WinCRT window procedure DoneWinCrt; Exit Exits immediately from the current block. procedure Exit; NB If the current block is the main program, Exit causes the program to terminate. Halt Stops program execution and returns to the operating system. procedure Halt [ ( Exitcode: Word ) ]; Exitcode is an optional expression that specifies the exit code of the program. Inc Increments a variable. procedure Inc(var X [ ; N: Longint ] );

Example

begin writeln('Press Enter...');

readln; clrScr;

end.

var i: integer;

begin i:=6; dec(i); { i=5 } dec(i,4){ i=1 }

end.

uses WinCrt;

begin Writeln('A WinCRT window.'); Writeln('Please hit return.'); Readln; DoneWinCRT;

end.

var

i: integer; begin for i:=1 to 100 do begin

if i>10 then exit; writeln(i); end; {loop will only get to 10} end.

begin if 1 = 1 then

begin if 2 = 2 then begin

if 3 = 3 then begin halt; end; end; end; writeln('This is never Printed'); end.

var i: integer;

begin i:=1; inc(i); { i=2 } inc(i,4){ i=6 }

end.

KeyPressed* Determines if a key has been pressed on the keyboard.

function KeyPressed: Boolean;

ReadKey* Reads a character from the keyboard.

function ReadKey: Char;

NB The character is not echoed to the screen.

begin repeat

Write('Xx'); until KeyPressed; DoneWincrt;

end.

var c: char;

begin writeln('Press a key'); c := Readkey; write(' You pressed ', c);

end.

* These functions are in the winCRT unit of Turbo Pascal for Windows. They are also available in the CRT unit of Free Pascal - to use them include the line 'uses CRT;' in the declaration of your program. ** This procedure is in the winCRT unit of Turbo Pascal, and is not available in FreePascal.

You might also like