Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 4/Functions: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-4C - Functions (author: Tao Yue, state: unchanged)
2-
3-Functions work the same way as procedures, but they always *return a single value* to the main program through its *own name*:
1+[[Basic Pascal Tutorial/Chapter 4/Parameters|◄]] | [[Basic Pascal Tutorial/Contents|▲]] | [[Basic Pascal Tutorial/Chapter 4/Scope|►]]
2+---|---|---
3+
4+4C - Functions (author: Tao Yue, state: unchanged)
45
5-``` pascal
6-function Name (parameter_list) : return_type;
6+Functions work the same way as procedures, but they always _return a single value_ to the main program through its _own name_ :
77```
8-
9-Functions are called in the main program by using them in expressions:
8+function Name (parameter_list) : return_type;
9+```
1010
11-``` pascal
11+Functions are called in the main program by using them in expressions:
12+```
1213a := Name (5) + 3;
1314```
1415
15-If your function has no argument, be careful not to use the name of the function on the right side of any equation inside the function. That is:
16-
17-``` pascal
16+If your function has no argument, be careful not to use the name of the function on the right side of any equation inside the function. That is:
17+```
1818function Name : integer;
19-begin
20- Name := 2;
21- Name := Name + 1
22-end.
19+ begin
20+ Name := 2;
21+ Name := Name + 1
22+ end.
2323```
2424
25-is a no-no. Instead of returning the value 3, as might be expected, this sets up an infinite recursive loop in certain language modes (e.g. {\$MODE DELPHI} or {\$MODE TP}; other modes require brackets for function call even if the brackets are empty due to no parameters being required for the particular function). Name will call Name, which will call Name, which will call Name, etc.
26-
27-The return value is set by assigning a value to the function identifier.
25+is a no-no. Instead of returning the value 3, as might be expected, this sets up an infinite recursive loop in certain language modes (e.g. {$MODE DELPHI} or {$MODE TP}; other modes require brackets for function calls even if the brackets are empty due to no parameters being required for the particular function). Name will call Name, which will call Name, which will call Name, etc.
2826
29-``` pascal
27+The return value is set by assigning a value to the function identifier.
28+```
3029Name := 5;
3130```
3231
33-It is generally bad programming form to make use of VAR parameters in functions -- functions should return only one value. You certainly don't want the sin function to change your pi radians to 0 radians because they're equivalent -- you just want the answer 0.
32+It is generally bad programming form to make use of VAR parameters in functions -- functions should return only one value. You certainly don't want the sin function to change your pi radians to 0 radians because they're equivalent -- you just want the answer 0.
3433
34+[[Basic Pascal Tutorial/Chapter 4/Parameters|◄]] | [[Basic Pascal Tutorial/Contents|▲]] | [[Basic Pascal Tutorial/Chapter 4/Scope|►]]
35+---|---|---
36+
3537---
36-*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Functions", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
38+*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Functions", as the Internet Archive kept it on 2026-01-29, last changed on 2025-03-03. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history