Basic Pascal

Back     

Pascal is one of the classic programming languages that gain popularity in the early 1980's and a company called Borland had made a very successful attempt when it comes to distribution and product usage and stability.

 

A very short summary is present here in this page and We hope to provide an insight with regards to Pascal the programming language itself.

 

 Declaration


procedure MyProc;

type

MyInteger = Integer;        {type }

var

x,y,z : MyInteger;

begin

        ....

        ...

end;        


procedure TDataTypes.SubrangesClick(Sender : TObject);

type

TValidYears = 1990..1994;

var

ValidYears : TValidYears;

Letters : 'A'..'Z';

MaxHeight : 2*(100-10)..800*2;

i1 : Longint;

r1 : Real;

Result : String;

begin


        i1 := 27 div 7;        

        str(i1,Result);        { convert to string }

        MessageDlg('Result 27 div 7 = ' + Result,

                        mtInformation,[mbOk],0);

        r1 := 27/7;

        { convert w/ fixed format }

        str(r1:20:18,Result);        

        MessageDlg('Result 27/7 (real) = ' + Result,

                        mtInformation,[mbOk],0);

end;


  LOOP


{ while ... do loop }


while b<=200 do

begin


Randomize;                { increase b a random number between 1 & 23 }

Inc(b, Random(23));

Inc(c);                        { increase c by 1 }

end;


{ repeat ... until loop }


repeat

.....

...

until b>200;


{ for loop }


for x := 1 to 100 do

Inc(Total, x);


{ Break and Continue }


while TRUE do

begin


        Inc(x);

        if (x mod 3) = 0 then Continue;

        if x > 100 then begin

         MessageDlg('Break encountered. Leaving while loop',

                         mtInformation,[mbOk],0);

        break;

end;


 Data Types

  • Ordinals

        - Integers

        - Booleans

        - Character

        - Enums

        - Subranges

  • Strings

        - Strings

        - PChar

        - Conversion

  • Reals

        - Real

        - Float

        - Comp

  • Variants

        - Variants

  • Structured

        - Arrays

        - Records

        - Sets

        - Files



  Expressions & Statements


var

l : Boolean;

g : Boolean;

begin

        l := 10 > 3;        { boolean test as true }

        if l then

         Memo1.Lines.Add('The Result is True.....')

        else

         Memo1.Lines.Add('The Result is False.....');


        { w/ logical and operator }

        g := (10 > 3) and (-1 > 0);

end;


{ Labels and GOTO statements, for jump'n to other }

{ part of the program body }


procedure TStatements.GotoButtonClick (Sender : TObject );

label Starter, Ender;

begin


MessageDlg('Before the Starter label',mtInformation,[mbOk],0);        


Starter:

MessageDlg('After the Starter label, before the goto',

                mtInformation,[mbOk],0);


goto Ender;                { jump here }

MessageDlg('After the goto Statement',

                mtInformation,[mbOk],0);


Ender:

MessageDlg('After the Ender Label',

                mtInformation,[mbOk],0);

end;


{ sample for enum statements, see under type below }


procedure TStatements.CaseButtonCLick(Sender : TObject);

type

TDaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,

                        Thursday, Friday, Saturday);

var

Today : TDaysOfWeek;

begin


        case Today of

         Sunday : MealOfTheDay := BroiledChicken;

         Monday : MealOfTheDay := Humburger;

         Tuesday : MealOfTheDay := PorkRoast;

         Wednesday: MealOfTheDay := Linguini;

         Thursday : MealOfTheDay := PattyMelt;

         Friday : MealOfTheDay := Veal;

         else          MealOfTheDay := BLT;

        end;

end;