Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Pascal Programming Language

1.926 Aufrufe

Veröffentlicht am

Concepts of Programming Language

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

Pascal Programming Language

  1. 1. 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
  2. 2. Outline • About Pascal (programming language) • General Program Skeleton • Pascal Hello World Example • Decision Making In Pascal • Supprogram In Pascal • Loop In Pascal • Array
  3. 3. 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.
  4. 4. General Program Skeleton • The basic syntax for a Pascal program:
  5. 5. 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.
  6. 6. Decision Making In Pascal • Decision Making In Pascal : - if - then statement - if-then-else Statement - Case Statement - Case Else Statement
  7. 7. 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;
  8. 8. 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;
  9. 9. Decision Making - case - of statement • The syntax of the case statement is: Similar to if statement Easier to read and understand Does not accept String variables case (expression) of L1 : S1; ... Ln : Sn; end;
  10. 10. Decision Making - case statement • Example case – of statement :
  11. 11. 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;
  12. 12. Decision Making - case -else statement • Example :
  13. 13. 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
  14. 14. 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;
  15. 15. FUNCTION • Example :
  16. 16. 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;
  17. 17. PROCEDURES • Example: procedure without parameters
  18. 18. 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.
  19. 19. 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.
  21. 21. 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;
  22. 22. 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 do begin The computer will do something; end;
  23. 23. 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>;
  24. 24. ARRAY IN PASCAL • The syntax for the Array as follows: Example: var array-name : array[range] of element-type;