+ All Categories
Home > Technology > Pascal Programming Language

Pascal Programming Language

Date post: 16-Apr-2017
Category:
Upload: reham-alblehid
View: 486 times
Download: 0 times
Share this document with a friend
24
Pascal Programming Language CSE 337 Concepts of Programming Languages Qassim University College of Computer – IT department Ms.Sadaf Ambreen Abbasi. Reham AL blihed Muna AL rajhi
Transcript
Page 1: Pascal Programming Language

Pascal Programming LanguageCSE 337 Concepts of Programming LanguagesQassim UniversityCollege of Computer – IT department

Ms.Sadaf Ambreen Abbasi.Reham AL blihedMuna AL rajhi

Page 2: Pascal Programming Language

Outline• About Pascal (programming language)• General Program Skeleton• Pascal Hello World Example

• Decision Making In Pascal

• Supprogram In Pascal

• Loop In Pascal

• Array

Page 3: Pascal Programming Language

About Pascal (programming language)

•Pascal- is a historically influential imperative and procedural programming language.

- designed in 1968–1969 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.

Page 4: Pascal Programming Language

General Program Skeleton• The basic syntax for a Pascal program:

Page 5: Pascal Programming Language

Pascal Hello World Example

• The first line of the program program HelloWorld; indicates the name of the program.

• begin and end statements are the main program block.

• The end statement indicating the end of the main program is followed by a full stop (.)

• The lines within (*...*) will be ignored by the compiler and it has been put to add a comment in the program.

• he statement writeln('Hello, World!'); function in Pascal used to display Message on the screen.

Page 6: Pascal Programming Language

Decision Making In Pascal

• Decision Making In Pascal :

- if - then statement

- if-then-else Statement

- Case Statement

- Case Else Statement

Page 7: Pascal Programming Language

Decision Making - if - then statement

• Syntax for if-then statement is:

If the Boolean expression evaluates to true, the statement executes. Otherwise, it is skipped.

if BooleanExpression then StatementIfTrue;

Page 8: Pascal Programming Language

Decision Making - if – then-else statement

• Syntax for the if-then-else statement is:

If the Boolean expression evaluates to FALSE, the statement following the else will be performed.

if BooleanExpression then StatementIfTrue else StatementIfFalse;

Page 9: Pascal Programming Language

Decision Making - case - of statement

• The syntax of the case statement is:

Similar to if statementEasier to read and understandDoes not accept String variables

case (expression) of L1 : S1; ... Ln : Sn; end;

Page 10: Pascal Programming Language

Decision Making - case statement

• Example case – of statement :

Page 11: Pascal Programming Language

Decision Making - case -else statement

• The syntax for the case-else statement is:

• It is similar to the if-then-else statements• Easier to read and understand

• Does not accept String variables

case (expression) of L1 : S1; L2 : S2; ... Ln : Sn; else Sm; end;

Page 12: Pascal Programming Language

Decision Making - case -else statement

• Example :

Page 13: Pascal Programming Language

SUPPROGRAM IN PASCAL

A subprogram is a program unit/module that performs a particular task.

Pascal provides two kinds of subprograms:

• Functions: these subprograms return a single value.

• Procedures: these subprograms do not return a value directly

Page 14: Pascal Programming Language

SUPPROGRAM IN PASCAL FUNCTION

• The general form of a function definition is as follows:

function name(argument(s): type1; argument(s): type2; ...): function_type; local declarations; begin ... < statements > ... name:= expression; end;

Page 15: Pascal Programming Language

FUNCTION• Example :

Page 16: Pascal Programming Language

PROCEDURES

• Used to separate code into section.

• Can be called by the main program, function or other procedures.

• Must be created above the main program.

• The general form of a procedure definition is as follows:

procedure name(argument(s): type1, argument(s): type 2, ... ) ; <local declarations>

begin <procedure body >

end;

Page 17: Pascal Programming Language

PROCEDURES

• Example: procedure without parameters

Page 18: Pascal Programming Language

PROCEDURES• PROCEDURES Pass by value: This method copies the actual value of an argument into the formal parameter of the subprogram. In this case, changes made to the parameter inside the subprogram have no effect on the argument.

• That means MyNumber and X have two different locations in memory.

Page 19: Pascal Programming Language

PROCEDURES• PROCEDURES Calling by reference• If we add the var keyword to the declaration of DoSomething's x parameter, things will

be different now:

This time MyNumber's value will be changed according to x, which means they are sharing the same memory location.

Page 20: Pascal Programming Language

LOOP IN PASCAL

• LOOP IN PASCAL

- WHILE - DO

- FOR-DO

- REPEAT UNTIL

Page 21: Pascal Programming Language

WHILE - DO LOOP• The syntax of a while-do loop is:

Where condition is a Boolean or relational expression, whose value would be true or false and the computer will do something is a simple statement or group of statements within begin ... end block.

While <condition> do begin The computer will do something; end;

Page 22: Pascal Programming Language

FOR-DO LOOP

• The syntax of for-do loop as follows:

for low to high do begin The computer will do something;end;

for high downto low dobegin The computer will do something;end;

Page 23: Pascal Programming Language

REPEAT UNTIL LOOP

• Unlike for and while loops, which test the loop condition at the top of the loop, the repeat ... until loop in Pascal checks its condition at the bottom of the loop.

• The syntax of the repeat until as follows: repeat

The computer will do something; until<condition>;

Page 24: Pascal Programming Language

ARRAY IN PASCAL

• The syntax for the Array as follows:

Example:

var array-name : array[range] of element-type;


Recommended