SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Presented by : 
Arinda Lailatul Karimah 4101412109 
Septi Ratnasari 4101412082
Description 
 A function is a group of statements that together 
perform a task. 
 Every Pascal program has at least one function which is 
the program itself, and all the most trivial programs can 
define additional functions. 
 A function declaration tells the compiler about a 
function's name, return type, and parameters. A 
function definition provides the actual body of the 
function.
 A function is similar to a procedure. 
 Procedures accept data or variables when they are 
executed. Functions also accept data, but have the ability 
to return a value to the procedure or program which 
requests it. 
 Functions are used to perform mathematical tasks like 
factorial calculations. 
 A function : 
1. begins with the keyword function 
2. is similar in structure to a procedure 
3. somewhere inside the code associated with the 
function, a value is assigned to the function name 
4. a function is used on the righth and side of an 
expression 
5. can only return a simple data type
 The only difference from the procedure is that the 
function return a value at the end. Note that a procedure 
cannot return a value. A function start and end in a 
similar way to that of a procedure. 
 If more than one value is required to be returned by a 
module, we should make use of the variable parameter. A 
function can have parameters too. If we change the sub-program 
from procedure to a function, of the previous 
program, there will be no difference in the output of the 
program. 
 Just make sure which one is best when we can to 
implement a module. For example, if we don't need to 
return any values, a procedure is more best. However if a 
value should be returned after the module is executed, 
function should be used instead.
 In Pascal, a function is defined using the function 
keyword. 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;
 A function definition in Pascal consists of a function 
header, local declarations and a function body. The 
function header consists of the keyword function and a 
name given to the function.
Here are all the parts of a function: 
1. Arguments: 
The argument(s) establish the linkage between the calling 
program and the function identifiers and also called the 
formal parameters. 
 A parameter is like a placeholder. When a function is 
invoked, we pass a value to the parameter. This value is 
referred to as actual parameter or argument. The 
parameter list refers to the type, order, and number of 
the parameters of a function. Use of such formal 
parameters is optional. These parameters may have 
standard data type, user-defined data type or subrange 
data type. 
 The formal parameters list appearing in the function 
statement could be simple or subscripted variables, 
arrays or structured variables, or subprograms.
2. Return Type: 
All functions must return a value, so all functions must 
be assigned a type. 
The function-type is the data type of the value the 
function returns. It may be standard, user-defined scalar 
or subrange type but it cannot be structured type.
3. Local declarations: 
local declarations refer to the declarations for labels, 
constants, variables, functions and procedures, which are 
application to the body of function only.
4. Function Body: 
The function body contains a collection of 
statements that define what the function does. 
It should always be enclosed between the 
reserved words begin and end. It is the part of a 
function where all computations are done. 
There must be an assignment statement of the 
type - name := expression; in the function body 
that assigns a value to the function name. This 
value is returned as and when the function is 
executed. The last statement in the body must 
be an end statement.
 Following is an example showing how to define a function in pascal: 
(* function returning the max between two numbers *) 
function max(num1, num2: integer): integer; 
var 
(* local variable declaration *) 
result: integer; 
begin 
if (num1 > num2) then 
result := num1 
else 
result := num2; 
max := result; 
end;
Function Declarations 
 A function declaration tells the compiler about a function 
name and how to call the function. The actual body of the 
function can be defined separately. 
 A function declaration has the following parts: 
function name(argument(s): type1; argument(s): type2; ...): 
function_type; 
 For the above defined function max(), following is the 
function declaration: 
function max(num1, num2: integer): integer;
 Function declaration is required when we define a 
function in one source file and we call that function in 
another file. In such case we should declare the function 
at the top of the file calling the function.
Calling a Function 
 While creating a function, we give a definition of what 
the function has to do. 
 To use a function, we will have to call that function to 
perform the defined task. When a program calls a 
function, program control is transferred to the called 
function. 
 A called function performs defined task and when its 
return statement is executed or when it last end 
statement is reached, it returns program control back to 
the main program.
To call a function we simply need to pass the required parameters 
along with function name and if function returns a value then we 
can store returned value. Following is a simple example to show 
the usage:
Assigning a value to a function identifier 
 The function's block definition must include a statement 
that assigns a value to the function's identifier. This is 
how a function gets a value that it can return to the 
caller. 
 If we omit this assignment statement, or the assignment 
statement does not get executed as a result of 
conditional statements in the function's code, then the 
function returns an undefined or potentially random 
value. If during the course of debugging a program we 
find our functions returning erratic values, be certain 
that the function identifier is correctly assigned a value.
Acceptable Function Return Values 
 The data type that a function returns can be any of the 
following: 
a. Any ordinal value, including Boolean, Byte, Char, Smallint, 
Integer, Word, Longint, and enumarated data types and 
user defined sub range types. 
b. Real, Single, Double, Extended and Comp data types, 
c. Pointer values 
d. Strings. 
 Functions may not return records or sets, although they may 
return pointers to records or sets.
Recursive Function 
 Functions may call themselves. Such a function is called a 
recursive function. A popular and simple example of a 
recursive function is a function that computes the factorial 
of a number. The factorial of a number n, is n * (n-1) * (n-2) 
... until n reaches 1.
Important note: 
The effect of short-circuit evaluation on functions 
 By default, Turbo Pascal generates short-circuit evaluation code, so it is 
possible that a function may not be called within a particular expression. 
For example, consider a function defined as: 
function ValueInRange ( X1 : Integer ) : Boolean; 
begin 
... 
if X1 > 0 then 
ValueInRange := True 
else 
ValueInRange := False; 
if X1 < LowestCoordinate then 
LowestCoordinate := X1; 
end;
 In this function, a global variable LowestCoordinate may 
have its value changed during the course of execution. If 
this function is called in an expression such as, 
if (X1<>X2) and ValueInRange(X1) then ...
Function as Parameter 
 A function may itself be passed to another function as a 
parameter value. To pass a requires that a type 
declaration define a procedure type that matches the 
appropriate function header. This type becomes the 
parameter type used in the procedure parameter list.
Fungsi Add
Fungsi Max-ab
Fungsi Genap - Ganjil
Fungsi Midpoint
Fungsi Phytagoras
Fungsi Luas 
Segitiga
Fungsi Luas 
Persegi Panjang
Fungsi Volume 
Balok
Pascal Functions Explained

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Function
FunctionFunction
Function
 
user defined function
user defined functionuser defined function
user defined function
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Java script function
Java script functionJava script function
Java script function
 
Chapter 13.1.6
Chapter 13.1.6Chapter 13.1.6
Chapter 13.1.6
 
Chapter 11 Function
Chapter 11 FunctionChapter 11 Function
Chapter 11 Function
 
C functions
C functionsC functions
C functions
 
Functions
FunctionsFunctions
Functions
 
Function
FunctionFunction
Function
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Recursion in c
Recursion in cRecursion in c
Recursion in c
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
User Defined Functions in C
User Defined Functions in CUser Defined Functions in C
User Defined Functions in C
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
Functions in python
Functions in python Functions in python
Functions in python
 
Unit 8
Unit 8Unit 8
Unit 8
 

Andere mochten auch

Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1Ayu Karisma Alfiana
 
Pemrograman komputer 9 (database)
Pemrograman komputer  9 (database)Pemrograman komputer  9 (database)
Pemrograman komputer 9 (database)jayamartha
 
Program pascal menghitung ipk
Program pascal menghitung ipkProgram pascal menghitung ipk
Program pascal menghitung ipkArjanggi Nv
 
4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.net4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.netRief Fiandi
 
Pengantar Pemrograman Visual II
Pengantar Pemrograman Visual IIPengantar Pemrograman Visual II
Pengantar Pemrograman Visual IIWahyu Primadi
 
Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2Ayu Karisma Alfiana
 
123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004Nurdin Al-Azies
 
03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net 03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net Ayu Karisma Alfiana
 
Algoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer IAlgoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer IChandra Septianoor
 
Materi Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis DesktopMateri Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis DesktopNaufal Arifudzaki
 
27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-iiAyu Karisma Alfiana
 
Part 10 pengantar basis data
Part 10 pengantar basis dataPart 10 pengantar basis data
Part 10 pengantar basis dataDermawan12
 
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalPerulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalTeknik Informatika UII
 
Pertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CPertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CNurdin Al-Azies
 
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)Nurdin Al-Azies
 
Membuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan javaMembuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan javaEko Kurniawan Khannedy
 
Aplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstopAplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstopalfian_nasir
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A ReviewFernando Torres
 

Andere mochten auch (20)

Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1Mi 02.-praktikum-pemrograman-visual-1
Mi 02.-praktikum-pemrograman-visual-1
 
Pemrograman komputer 9 (database)
Pemrograman komputer  9 (database)Pemrograman komputer  9 (database)
Pemrograman komputer 9 (database)
 
Program pascal menghitung ipk
Program pascal menghitung ipkProgram pascal menghitung ipk
Program pascal menghitung ipk
 
4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.net4 tip dan trik database dalam vb.net
4 tip dan trik database dalam vb.net
 
Pengantar Pemrograman Visual II
Pengantar Pemrograman Visual IIPengantar Pemrograman Visual II
Pengantar Pemrograman Visual II
 
Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2Mi 03.-praktikum-pemrograman-visual-2
Mi 03.-praktikum-pemrograman-visual-2
 
123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004123 Tip & Trik ActionScript Flash MX 2004
123 Tip & Trik ActionScript Flash MX 2004
 
03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net 03. prak.-pemrograman-visual-i-vb.net
03. prak.-pemrograman-visual-i-vb.net
 
Algoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer IAlgoritma dan Pemprograman Komputer I
Algoritma dan Pemprograman Komputer I
 
Materi Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis DesktopMateri Pemrograman Berbasis Desktop
Materi Pemrograman Berbasis Desktop
 
27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii27. prak.-algoritma-pemrograman-ii
27. prak.-algoritma-pemrograman-ii
 
05. prak.-pemrograman-visual-ii
05. prak.-pemrograman-visual-ii05. prak.-pemrograman-visual-ii
05. prak.-pemrograman-visual-ii
 
Part 10 pengantar basis data
Part 10 pengantar basis dataPart 10 pengantar basis data
Part 10 pengantar basis data
 
Perulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam PascalPerulangan While do, For to do, dan Repeat Until dalam Pascal
Perulangan While do, For to do, dan Repeat Until dalam Pascal
 
Pertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman CPertemuan 05 - 06 Pemrograman C
Pertemuan 05 - 06 Pemrograman C
 
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
Buku Studi Islam 3 (Dr. Ahmad Alim, LC. MA.)
 
Basis data
Basis dataBasis data
Basis data
 
Membuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan javaMembuat aplikasi sederhana menggunakan java
Membuat aplikasi sederhana menggunakan java
 
Aplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstopAplikasi penjualan busana fashion berbasis dekstop
Aplikasi penjualan busana fashion berbasis dekstop
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 

Ähnlich wie Pascal Functions Explained

Ähnlich wie Pascal Functions Explained (20)

User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
Functions
FunctionsFunctions
Functions
 
Functions
Functions Functions
Functions
 
Chapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdfChapter_1.__Functions_in_C++[1].pdf
Chapter_1.__Functions_in_C++[1].pdf
 
Chapter 1. Functions in C++.pdf
Chapter 1.  Functions in C++.pdfChapter 1.  Functions in C++.pdf
Chapter 1. Functions in C++.pdf
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
C functions list
C functions listC functions list
C functions list
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
 
Function in c
Function in cFunction in c
Function in c
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 
Functions
FunctionsFunctions
Functions
 
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptxCH.4FUNCTIONS IN C_FYBSC(CS).pptx
CH.4FUNCTIONS IN C_FYBSC(CS).pptx
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Module 3-Functions
Module 3-FunctionsModule 3-Functions
Module 3-Functions
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
PSPC-UNIT-4.pdf
PSPC-UNIT-4.pdfPSPC-UNIT-4.pdf
PSPC-UNIT-4.pdf
 

Mehr von Septi Ratnasari

Sanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkunganSanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkunganSepti Ratnasari
 
Kedudukan BK dalam Pendidikan
Kedudukan BK dalam PendidikanKedudukan BK dalam Pendidikan
Kedudukan BK dalam PendidikanSepti Ratnasari
 
English Conversation in the School
English Conversation in the SchoolEnglish Conversation in the School
English Conversation in the SchoolSepti Ratnasari
 
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...Septi Ratnasari
 

Mehr von Septi Ratnasari (11)

Pengujian Hipotesis
Pengujian HipotesisPengujian Hipotesis
Pengujian Hipotesis
 
Sanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkunganSanitasi dan Kesehatan lingkungan
Sanitasi dan Kesehatan lingkungan
 
Hakikat Pendidikan
Hakikat PendidikanHakikat Pendidikan
Hakikat Pendidikan
 
Curved Sides
Curved SidesCurved Sides
Curved Sides
 
Kedudukan BK dalam Pendidikan
Kedudukan BK dalam PendidikanKedudukan BK dalam Pendidikan
Kedudukan BK dalam Pendidikan
 
Graf Pohon
Graf PohonGraf Pohon
Graf Pohon
 
Circle Terminology
Circle TerminologyCircle Terminology
Circle Terminology
 
English Conversation in the School
English Conversation in the SchoolEnglish Conversation in the School
English Conversation in the School
 
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
Perpustakaan sebagai Media dalam Implementasi Strategi Pembelajaran Inkuiri (...
 
Permasalahan Sampah
Permasalahan SampahPermasalahan Sampah
Permasalahan Sampah
 
Mathematical Logic
Mathematical LogicMathematical Logic
Mathematical Logic
 

Kürzlich hochgeladen

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptxmary850239
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 

Kürzlich hochgeladen (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx4.11.24 Mass Incarceration and the New Jim Crow.pptx
4.11.24 Mass Incarceration and the New Jim Crow.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 

Pascal Functions Explained

  • 1. Presented by : Arinda Lailatul Karimah 4101412109 Septi Ratnasari 4101412082
  • 2. Description  A function is a group of statements that together perform a task.  Every Pascal program has at least one function which is the program itself, and all the most trivial programs can define additional functions.  A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function.
  • 3.  A function is similar to a procedure.  Procedures accept data or variables when they are executed. Functions also accept data, but have the ability to return a value to the procedure or program which requests it.  Functions are used to perform mathematical tasks like factorial calculations.  A function : 1. begins with the keyword function 2. is similar in structure to a procedure 3. somewhere inside the code associated with the function, a value is assigned to the function name 4. a function is used on the righth and side of an expression 5. can only return a simple data type
  • 4.  The only difference from the procedure is that the function return a value at the end. Note that a procedure cannot return a value. A function start and end in a similar way to that of a procedure.  If more than one value is required to be returned by a module, we should make use of the variable parameter. A function can have parameters too. If we change the sub-program from procedure to a function, of the previous program, there will be no difference in the output of the program.  Just make sure which one is best when we can to implement a module. For example, if we don't need to return any values, a procedure is more best. However if a value should be returned after the module is executed, function should be used instead.
  • 5.  In Pascal, a function is defined using the function keyword. 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;
  • 6.  A function definition in Pascal consists of a function header, local declarations and a function body. The function header consists of the keyword function and a name given to the function.
  • 7. Here are all the parts of a function: 1. Arguments: The argument(s) establish the linkage between the calling program and the function identifiers and also called the formal parameters.  A parameter is like a placeholder. When a function is invoked, we pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Use of such formal parameters is optional. These parameters may have standard data type, user-defined data type or subrange data type.  The formal parameters list appearing in the function statement could be simple or subscripted variables, arrays or structured variables, or subprograms.
  • 8. 2. Return Type: All functions must return a value, so all functions must be assigned a type. The function-type is the data type of the value the function returns. It may be standard, user-defined scalar or subrange type but it cannot be structured type.
  • 9. 3. Local declarations: local declarations refer to the declarations for labels, constants, variables, functions and procedures, which are application to the body of function only.
  • 10. 4. Function Body: The function body contains a collection of statements that define what the function does. It should always be enclosed between the reserved words begin and end. It is the part of a function where all computations are done. There must be an assignment statement of the type - name := expression; in the function body that assigns a value to the function name. This value is returned as and when the function is executed. The last statement in the body must be an end statement.
  • 11.  Following is an example showing how to define a function in pascal: (* function returning the max between two numbers *) function max(num1, num2: integer): integer; var (* local variable declaration *) result: integer; begin if (num1 > num2) then result := num1 else result := num2; max := result; end;
  • 12.
  • 13. Function Declarations  A function declaration tells the compiler about a function name and how to call the function. The actual body of the function can be defined separately.  A function declaration has the following parts: function name(argument(s): type1; argument(s): type2; ...): function_type;  For the above defined function max(), following is the function declaration: function max(num1, num2: integer): integer;
  • 14.  Function declaration is required when we define a function in one source file and we call that function in another file. In such case we should declare the function at the top of the file calling the function.
  • 15. Calling a Function  While creating a function, we give a definition of what the function has to do.  To use a function, we will have to call that function to perform the defined task. When a program calls a function, program control is transferred to the called function.  A called function performs defined task and when its return statement is executed or when it last end statement is reached, it returns program control back to the main program.
  • 16. To call a function we simply need to pass the required parameters along with function name and if function returns a value then we can store returned value. Following is a simple example to show the usage:
  • 17.
  • 18. Assigning a value to a function identifier  The function's block definition must include a statement that assigns a value to the function's identifier. This is how a function gets a value that it can return to the caller.  If we omit this assignment statement, or the assignment statement does not get executed as a result of conditional statements in the function's code, then the function returns an undefined or potentially random value. If during the course of debugging a program we find our functions returning erratic values, be certain that the function identifier is correctly assigned a value.
  • 19. Acceptable Function Return Values  The data type that a function returns can be any of the following: a. Any ordinal value, including Boolean, Byte, Char, Smallint, Integer, Word, Longint, and enumarated data types and user defined sub range types. b. Real, Single, Double, Extended and Comp data types, c. Pointer values d. Strings.  Functions may not return records or sets, although they may return pointers to records or sets.
  • 20. Recursive Function  Functions may call themselves. Such a function is called a recursive function. A popular and simple example of a recursive function is a function that computes the factorial of a number. The factorial of a number n, is n * (n-1) * (n-2) ... until n reaches 1.
  • 21.
  • 22. Important note: The effect of short-circuit evaluation on functions  By default, Turbo Pascal generates short-circuit evaluation code, so it is possible that a function may not be called within a particular expression. For example, consider a function defined as: function ValueInRange ( X1 : Integer ) : Boolean; begin ... if X1 > 0 then ValueInRange := True else ValueInRange := False; if X1 < LowestCoordinate then LowestCoordinate := X1; end;
  • 23.  In this function, a global variable LowestCoordinate may have its value changed during the course of execution. If this function is called in an expression such as, if (X1<>X2) and ValueInRange(X1) then ...
  • 24. Function as Parameter  A function may itself be passed to another function as a parameter value. To pass a requires that a type declaration define a procedure type that matches the appropriate function header. This type becomes the parameter type used in the procedure parameter list.
  • 25.
  • 28. Fungsi Genap - Ganjil