0% found this document useful (0 votes)
11 views18 pages

Pseudocode Notes

The document outlines fundamental concepts in programming, including data types, variable declarations, constants, arrays, and user-defined data types. It provides guidelines for writing pseudocode, including syntax for operations, input/output, and control structures like IF and CASE statements. Additionally, it covers common functions for string manipulation, arithmetic, and date handling.

Uploaded by

tanaymalde8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views18 pages

Pseudocode Notes

The document outlines fundamental concepts in programming, including data types, variable declarations, constants, arrays, and user-defined data types. It provides guidelines for writing pseudocode, including syntax for operations, input/output, and control structures like IF and CASE statements. Additionally, it covers common functions for string manipulation, arithmetic, and date handling.

Uploaded by

tanaymalde8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Variables, constants and data types

Data Types
The following keywords are used to designate some basic data types:

• INTEGER a whole number


• REAL a number capable of containing a fractional part
• CHAR a single character
• STRING a sequence of zero or more characters
• BOOLEAN the logical values TRUE and FALSE
• DATE a valid calendar date

Literals
Literals of the above data types are written as follows:

• Integer Written as normal in the denary system, e.g. 5, -3

Always written with at least one digit on either side of the decimal point, zeros being
• Real
added if necessary, e.g. 4.7, 0.3, -4.0, 0.0

• Char A single character delimited by single quotes e.g. ꞌxꞌ, ꞌCꞌ, ꞌ@ꞌ

Delimited by double quotes. A string may contain no characters (i.e. the empty string)
• String
e.g. "This is a string", ""

• Boolean TRUE, FALSE

This will normally be written in the format dd/mm/yyyy. However, it is good practice to
• Date state explicitly that this value is of data type DATE and to explain the format (as the
convention for representing dates varies across the world).

Identifiers
Identifiers (the names given to variables, constants, procedures and functions) are in mix case. They can only
contain letters (A–Z, a–z), digits (0–9) and the underscore character ( _ ). They must start with a letter and not
a digit. Accented letters should not be used.

As in programming, it is good practice to use identifier names that describe the variable, procedure or function
they refer to. Single letters may be used where these are conventional (such as i and j when dealing with
array indices, or X and Y when dealing with coordinates) as these are made clear by the convention.

Keywords identified elsewhere in this guide should never be used as variables.

Identifiers should be considered case insensitive, for example, Countdown and CountDown should not
be used as separate variables.
Variable declarations
It is good practice to declare variables explicitly in pseudocode.

Declarations are made as follows:

DECLARE <identifier> : <data type>

Example – variable declarations


DECLARE Counter : INTEGER
DECLARE TotalToPay : REAL
DECLARE GameOver : BOOLEAN

Constants
It is good practice to use constants if this makes the pseudocode more readable, as an identifier is more
meaningful in many cases than a literal. It also makes the pseudocode easier to update if the value of the
constant changes.

Constants are normally declared at the beginning of a piece of pseudocode (unless it is desirable to restrict
the scope of the constant).

Constants are declared by stating the identifier and the literal value in the following format:

CONSTANT <identifier> = <value>

Example – CONSTANT declarations


CONSTANT HourlyRate = 6.50
CONSTANT DefaultText = "N/A"

Only literals can be used as the value of a constant. A variable, another constant or an expression must
never be used.

Assignments
The assignment operator is ← .

Assignments should be made in the following format:

<identifier> ← <value>

The identifier must refer to a variable (this can be an individual element in a data structure such as an array or
an abstract data type). The value may be any expression that evaluates to a value of the same data type as
the variable.

Example – assignments
Counter ← 0
Counter ← Counter + 1
TotalToPay ← NumberOfHours * HourlyRate
Arrays

Declaring arrays
Arrays are considered to be fixed-length structures of elements of identical data type, accessible by
consecutive index (subscript) numbers. It is good practice to explicitly state what the lower bound of the
array (i.e. the index of the first element) is because this defaults to either 0 or 1 in different systems.
Generally, a lower bound of 1 will be used.

Square brackets are used to indicate the array indices.

A One-dimensional array is declared as follows:

DECLARE <identifier> : ARRAY[<lower>:<upper>] OF <data type>

A two-dimensional array is declared as follows:

DECLARE <identifier> : ARRAY[<lower1>:<upper1>,<lower2>:<upper2>] OF <data


type>

Example – array declaration


DECLARE StudentNames : ARRAY[1:30] OF STRING
DECLARE NoughtsAndCrosses : ARRAY[1:3,1:3] OF CHAR

Using arrays
Array index values may be literal values or expressions that evaluate to a valid integer value.

Example – Accessing individual array elements


StudentNames[1] ← "Ali"
NoughtsAndCrosses[2,3] ← ꞌXꞌ
StudentNames[n+1] ← StudentNames[n]

Arrays can be used in assignment statements (provided they have same size and data type). The following is
therefore allowed:

Example – Accessing a complete array


SavedGame ← NoughtsAndCrosses

A statement should not refer to a group of array elements individually. For example, the following
construction should not be used.

StudentNames [1 TO 30] ← ""

Instead, an appropriate loop structure is used to assign the elements individually. For example:

Example – assigning a group of array elements


FOR Index ← 1 TO 30
StudentNames[Index] ← ""
NEXT Index
User-defined data types
Defining user-defined data types
A user-defined non-composite data type with a list of possible values is called an enumerated data type.
The enumerated type should be declared as follows:

TYPE <identifier> = (value1, value2, value3, ...)

Example – declaration of enumerated type


This enumerated type holds data about seasons of the year.

TYPE Season = (Spring, Summer, Autumn, Winter)

A user-defined non-composite data type referencing a memory location is called a pointer.


The pointer should be declared as follows:

TYPE <pointer> = ^<Typename>

Example – declaration of pointer type


TYPE TAddPointer = ^INTEGER

A composite data type is a collection of data that can consist of different data types, grouped under one
identifier. The composite type should be declared as follows:

TYPE <identifier1>
DECLARE <identifier2> : <data type>
DECLARE <identifier3> : <data type>
...
ENDTYPE

Example – declaration of composite type


This user-defined data type holds data about a student.

TYPE Student
DECLARE Surname : STRING
DECLARE FirstName : STRING
DECLARE DateOfBirth : DATE
DECLARE YearGroup : INTEGER
DECLARE FormGroup : CHAR
ENDTYPE
Using user-defined data types
When a user-defined data type has been defined it can be used in the same way as any other data type in
declarations.

Variables of a user-defined data type can be assigned to each other. Individual data items are accessed
using dot notation.

Example – using user-defined data types


This pseudocode uses the user-defined type Student, Season and TAddPointer defined in
the previous section.

DECLARE Pupil1 : Student


DECLARE Pupil2 : Student
DECLARE Form : ARRAY[1:30] OF Student
DECLARE ThisSeason : Season
DECLARE NextSeason : Season
DECLARE MyAddPointer : TAddPointer

Pupil1.Surname ← "Johnson"
Pupil1.Firstname ← "Leroy"
Pupil1.DateOfBirth ← 02/01/2005
Pupil1.YearGroup ← 6
Pupil1.FormGroup ← ꞌAꞌ

Pupil2 ← Pupil1

FOR Index ← 1 TO 30
Form[Index].YearGroup ← Form[Index].YearGroup + 1
NEXT INDEX

ThisSeason ← Spring
MyAddPointer ← ^ThisSeason
NextSeason ← MyAddPointer^ + 1
// pointer is dereferenced to access the value stored
at the address
Common operations

Input and output


Values are input using the INPUT command as follows:

INPUT <identifier>

The identifier should be a variable (that may be an individual element of a data structure such as an array, or
a custom data type).

Values are output using the OUTPUT command as follows:

OUTPUT <value(s)>

Several values, separated by commas, can be output using the same command.

Example – INPUT and OUTPUT statements


INPUT Answer
OUTPUT Score
OUTPUT "You have ", Lives, " lives left"

Arithmetic operations
Standard arithmetic operator symbols are used:

+ Addition

- Subtraction

* Multiplication

/ Division

Care should be taken with the division operation: the resulting value should be of data type REAL, even if the
operands are integers.

Multiplication and division have higher precedence over addition and subtraction (this is the normal
mathematical convention). However, it is good practice to make the order of operations in complex
expressions explicit by using parentheses.

Relational operations
The following symbols are used for relational operators (also known as comparison operators):

> Greater than


< Less than
>= Greater than or equal to
<= Less than or equal to
= Equal to
<> Not equal to

The result of these operations is always of data type BOOLEAN.

In complex expressions it is advisable to use parentheses to make the order of operations explicit.
Note: An error occurs if a function call is not properly formed, or if the parameters are incorrect.

STRING Functions

LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns leftmost x characters from ThisString

Example: LEFT("ABCDEFGH", 3) returns "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING


returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING


returns a string of length y starting at position x from ThisString

Example: MID("ABCDEFGH", 2, 3) returns "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER


returns the integer value representing the length of ThisString

Example: LENGTH("Happy Days") returns 10

LCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the lower case equivalent of ThisChar
Characters that are not upper case alphabetic are returned unchanged

Example: LCASE('W') returns 'w'

UCASE(ThisChar : CHAR) RETURNS CHAR


returns the character value representing the upper case equivalent of ThisChar
Characters that are not lower case alphabetic are returned unchanged

Example: UCASE('a') returns 'A'

TO_UPPER(ThisString : STRING) RETURNS STRING


returns a string formed by converting all characters of ThisString to upper case

Example: TO_UPPER("Error 803") returns "ERROR 803"

TO_LOWER(ThisString : STRING) RETURNS STRING


returns a string formed by converting all characters of ThisString to lower case

Example: TO_LOWER("JIM 803") returns "jim 803"

NUM_TO_STR(x : <data type>) RETURNS STRING


returns a string representation of a numeric value
Note: <data type> may be REAL or INTEGER

Example: NUM_TO_STR(87.5) returns "87.5"


STR_TO_NUM(x : <data type1>) RETURNS <data type2>
returns a numeric representation of a string
Note: <data type1> may be CHAR or STRING
Note: <data type2> may be REAL or INTEGER

Example: STR_TO_NUM("23.45") returns 23.45

IS_NUM(ThisString : STRING) RETURNS BOOLEAN


returns the value TRUE if ThisString represents a valid numeric value
Note: <data type> may be CHAR or STRING

Example: IS_NUM("12.36") returns TRUE


Example: IS_NUM("-12.36") returns TRUE
Example: IS_NUM("12.3a") returns FALSE

ASC(ThisChar : CHAR) RETURNS INTEGER


returns an integer value (the ASCII value) of ThisChar

Example: ASC('A') returns 65

CHR(x : INTEGER) RETURNS CHAR


returns the character whose integer value (the ASCII value) is x

Example: CHR(87)returns 'W'

NUMERIC Functions

INT(x : REAL) RETURNS INTEGER


returns the integer part of x

Example: INT(27.5415) returns 27

RAND(x : INTEGER) RETURNS REAL


returns a real number in the range 0 to x (not inclusive of x)

Example: RAND(87) could return 35.43

DATE Functions

Note: Date format is assumed to be DDMMYYYY unless otherwise stated.

DAY(ThisDate : DATE) RETURNS INTEGER


returns the current day number from ThisDate

Example: DAY(4/10/2003) returns 4

MONTH(ThisDate : DATE) RETURNS INTEGER


returns the current month number from ThisDate

Example: MONTH(4/10/2003) returns 10


YEAR(ThisDate : DATE) RETURNS INTEGER
returns the current year number from ThisDate

Example: YEAR(4/10/2003) returns 2003

DAYINDEX(ThisDate : DATE) RETURNS INTEGER


returns the current day index number from ThisDate where Sunday = 1, Monday = 2,
Tuesday = 3 etc.

Example: DAYINDEX(12/05/2020) returns 3

SETDATE(Day, Month, Year : INTEGER) RETURNS DATE


returns a variable of type DATE

NOW() RETURNS DATE


returns the current date

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER


returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

OTHER Functions
EOF(FileName : STRING) RETURNS BOOLEAN
returns TRUE if there are no more lines to be read from file FileName

Note: This function will generate an ERROR if the file is not already open in READ mode

OPERATORS

The only logic operators (also called relational operators) usedare AND, OR and NOT. The operands and
results of theseoperations arealways of data type BOOLEAN.

Concatenates (joins) two strings


& Example: "Summer" & " " & "Pudding" evaluates to "Summer Pudding"
Note: This operator may also be used to concatenate a character with a string
Performs a logical AND on two Boolean values
AND
Example: TRUE AND FALSE evaluates to FALSE
Performs a logical OR on two Boolean values
OR
Example: TRUE OR FALSE evaluates to TRUE
Performs a logical NOT on a Boolean value
NOT
Example: NOT TRUE evaluates to FALSE
Finds the remainder when one number is divided by another
MOD
Example: 10 MOD 3 evaluates to 1
Finds the quotient when one number is divided by another
DIV
Example 10 DIV 3 evaluates to 3

Note: An error is generated if an operator is used with a value or values of an incorrect type.
Selection

IF statements
IF statements may or may not have an ELSE clause.

IF statements without an else clause are written as follows:

IF
<condition>
THEN
<statement(s)>
ENDIF

IF statements with an else clause are written as follows:

IF
<condition>
THEN
<statement(s)>
ELSE
<statement(s)>
ENDIF

Note, due to space constraints, the THEN and ELSE clauses may only be indented by two spaces rather than
three. (They are, in a sense, a continuation of the IF statement rather than separate statements).

When IF statements are nested, the nesting should continue the indentation of two spaces. In particular,
run-on THEN IF and ELSE IF lines should be avoided.

Example – nested IF statements


IF ChallengerScore > ChampionScore
THEN
IF ChallengerScore > HighestScore
THEN
OUTPUT ChallengerName, " is champion and highest scorer"
ELSE
OUTPUT Player1Name, " is the new champion"
ENDIF
ELSE
OUTPUT ChampionName, " is still the champion"
IF ChampionScore > HighestScore
THEN
OUTPUT ChampionName, " is also the highest scorer"
ENDIF
ENDIF
CASE statements
CASE statements allow one out of several branches of code to be executed, depending on the value of a
variable.

CASE statements are written as follows:

CASE OF <identifier>
<value 1> : <statement1>
<statement2>
...
<value 2> : <statement1>
<statement2>
...
...
ENDCASE

An OTHERWISE clause can be the last case:

CASE OF <identifier>
<value 1> : <statement1>
<statement2>
...
<value 2> : <statement1>
<statement2>
...
OTHERWISE : <statement1>
<statement2>
...
ENDCASE

Each value may be represented by a range, for example:

<value1> TO <value2> : <statement1>


<statement2>
...

Note that the case clauses are tested in sequence. When a case that applies is found, its statement is
executed and the CASE statement is complete. Control is passed to the statement after the ENDCASE. Any
remaining cases are not tested.

If present, an OTHERWISE clause must be the last case. Its statement will be executed if none of the
preceding cases apply.

Example – formatted CASE statement


INPUT Move
CASE OF Move
ꞌWꞌ : Position ← Position − 10
ꞌSꞌ : Position ← Position + 10
ꞌAꞌ : Position ← Position − 1
ꞌDꞌ : Position ← Position + 1
OTHERWISE : CALL Beep
ENDCASE
Iteration (repetition)

Count-controlled (FOR) loops


Count-controlled loops are written as follows:

FOR <identifier> ← <value1> TO <value2>


<statement(s)>
NEXT <identifier>

The identifier must be a variable of data type INTEGER, and the values should be expressions that evaluate
to integers.

The variable is assigned each of the integer values from value1 to value2 inclusive, running the statements
inside the FOR loop after each assignment. If value1 = value2 the statements will be executed once, and if
value1 > value2 the statements will not be executed.

It is good practice to repeat the identifier after NEXT, particularly with nested FOR loops. An increment can be
specified as follows:

FOR <identifier> ← <value1> TO <value2> STEP <increment>


<statement(s)>
NEXT <identifier>

The increment must be an expression that evaluates to an integer. In this case the identifier will be
assigned the values from value1 in successive increments of increment until it reaches value2. If it goes
past value2, the loop terminates. The increment can be negative.

Example – nested FOR loops


Total ← 0
FOR Row ← 1 TO MaxRow
RowTotal ← 0
FOR Column ← 1 TO 10
RowTotal ← RowTotal + Amount[Row, Column]
NEXT Column
OUTPUT "Total for Row ", Row, " is ", RowTotal
Total ← Total + RowTotal
NEXT Row
OUTPUT "The grand total is ", Total

Post-condition (REPEAT) loops


Post-condition loops are written as follows:

REPEAT
<Statement(s)>
UNTIL <condition>

The condition must be an expression that evaluates to a Boolean.


The statements in the loop will be executed at least once. The condition is tested after the statements are
executed and if it evaluates to TRUE the loop terminates, otherwise the statements are executed again.

Example – REPEAT UNTIL statement


REPEAT
OUTPUT "Please enter the password"
INPUT Password
UNTIL Password = "Secret"

Pre-condition (WHILE) loops


Pre-condition loops are written as follows:

WHILE <condition>
<statement(s)>
ENDWHILE

The condition must be an expression that evaluates to a Boolean.

The condition is tested before the statements, and the statements will only be executed if the condition
evaluates to TRUE. After the statements have been executed the condition is tested again. The loop
terminates when the condition evaluates to FALSE.

The statements will not be executed if, on the first test, the condition evaluates to FALSE.

Example – WHILE loop


WHILE Number > 9
Number ← Number – 9
ENDWHILE
Procedures and functions
Defining and calling procedures
A procedure with no parameters is defined as follows:

PROCEDURE <identifier>
<statement(s)>
ENDPROCEDURE

A procedure with parameters is defined as follows:

PROCEDURE<identifier>(<param1> : <datatype>, <param2> : <datatype>...)


<statement(s)>
ENDPROCEDURE

The <identifier> is the identifier used to call the procedure. Where used, param1, param2 etc. are
identifiers for the parameters of the procedure. These will be used as variables in the statements of the
procedure.

Procedures defined as above should be called as follows, respectively:

CALL <identifier>

CALL <identifier>(Value1, Value2, ...)

These calls are complete program statements.

When parameters are used, Value1, Value2,... must be of the correct data type and in the same
sequence as in the definition of the procedure.
Unless otherwise stated, it should be assumed that parameters are passed by value. (See section 8.3).

Example – use of procedures with and without parameters


PROCEDURE DefaultSquare
CALL Square(100)
ENDPROCEDURE

PROCEDURE Square(Size : INTEGER)


FOR Side ← 1 TO 4
CALL MoveForward (Size)
CALL Turn (90)
NEXT Side
ENDPROCEDURE

IF Size = Default
THEN
CALL DefaultSquare
ELSE
CALL Square(Size)
ENDIF
Defining and calling functions
Functions operate in a similar way to procedures, except that in addition they return a single value to the point
at which they are called. Their definition includes the data type of the value returned.

A function with no parameters is defined as follows:

FUNCTION <identifier> RETURNS <data type>


<statement(s)>
ENDFUNCTION

A function with parameters is defined as follows:

FUNCTION <identifier>(<param1> : <datatype>, <param2> :


<datatype>,...)RETURNS <data type>
<statement(s)>
ENDFUNCTION

The keyword RETURN is used as one of the statements within the body of the function to specify the value to
be returned. Normally, this will be the last statement in the function definition.

Because a function returns a value that is used when the function is called, function calls are not complete
program statements. The keyword CALL should not be used when calling a function. Functions should only
be called as part of an expression. When the RETURN statement is executed, the value returned replaces the
function call in the expression and the expression is then evaluated.

Example – definition and use of a function


FUNCTION Max(Number1:INTEGER, Number2:INTEGER) RETURNS INTEGER
IF Number1 > Number2
THEN
RETURN Number1
ELSE
RETURN Number2
ENDIF
ENDFUNCTION

OUTPUT "Penalty Fine = ", Max(10, Distance*2)

Passing parameters by value or by reference


To specify whether a parameter is passed by value or by reference, the keywords BYVAL and BYREF precede
the parameter in the definition of the procedure. If there are several parameters, they should all be passed by
the same method and the BYVAL or BYREF keyword need not be repeated.

Example – passing parameters by reference


PROCEDURE SWAP(BYREF X : INTEGER, Y : INTEGER)
Temp ← X
X ← Y
Y ← Temp
ENDPROCEDURE

If the method for passing parameters is not specified, passing by value is assumed. How this should
be called and how it operates has already been explained in Section 8.1.

Parameters should not be passed by reference to a function.


File handling

Handling text files


Text files consist of lines of text that are read or written consecutively as strings.

A file must be opened in a specified mode before any file operations are attempted. This is written
as follows:

OPENFILE <File identifier> FOR <File mode>

The file identifier may be a literal string containing the file names, or a variable of type STRING that has been
assigned the file name.

The following file modes are used:

• READ for data to be read from the file


• WRITE for data to be written to the file. A new file will be created and any existing data in the
file will be lost.
• APPEND for data to be added to the file, after any existing data.

A file should be opened in only one mode at a time.

Data is read from the file (after the file has been opened in READ mode) using the READFILE command as
follows:

READFILE <File Identifier>, <Variable>

The Variable should be of data type STRING. When the command is executed, the next line of
text in the file is read and assigned to the variable.

The function EOF is used to test whether there are any more lines to be read from a given file. It is called as
follows:

EOF(<File Identifier>)

This function returns TRUE if there are no more lines to read (or if an empty file has been opened in READ
mode) and FALSE otherwise.

Data is written into the file (after the file has been opened in WRITE or APPEND mode) using the
WRITEFILE command as follows:

WRITEFILE <File identifier> , <data>

Files should be closed when they are no longer needed using the CLOSEFILE command as

follows:

CLOSEFILE <File identifier>


Example – file handling operations
This example uses the operations together, to copy all the lines from FileA.txt to FileB.txt,
replacing any blank lines by a line of dashes.

DECLARE LineOfText : STRING


OPENFILE "FileA.txt" FOR READ
OPENFILE "FileB.txt" FOR WRITE
WHILE NOT EOF("FileA.txt")
READFILE "FileA.txt", LineOfText
IF LineOfText = ""
THEN
WRITEFILE "FileB.txt", "-------------------------"
ELSE
WRITEFILE "FILEB.txt", LineOfText
ENDIF
ENDWHILE
CLOSEFILE "FileA.txt"
CLOSEFILE "FileB.txt"

Handling random files


Random files contain a collection of data, normally as records of fixed length. They can be thought of as
having a file pointer which can be moved to any location or address in the file. The record at that location
can then be read or written.

Random files are opened using the RANDOM file mode as follows:

OPENFILE <File identifier> FOR RANDOM

As with text files, the file identifier will normally be the name of the file.

The SEEK command moves the file pointer to a given location:

SEEK <File identifier>, <address>

The address should be an expression that evaluates to an integer which indicates the location of a record to
be read or written. This is usually the number of records from the beginning of the file. It is good practice to
explain how the addresses are computed.

The command GETRECORD should be used to read the record at the file pointer:

GETRECORD <File identifier>, <Variable>

When this command is executed, the variable is assigned to the record that is read, and must be of the
appropriate data type for that record (usually a user-defined type).

The command PUTRECORD is used to write a record into the file at the file pointer:

PUTRECORD <File identifier>, <Variable>

When this command is executed, the data in the variable is inserted into the record at the file pointer. Any
data that was previously at this location will be replaced.
Example – handling random files
The records from positions 10 to 20 of a file StudentFile.Dat are moved to the next position and
a new record is inserted into position 10. The example uses the user-defined type Student defined
in Section 4.1.

DECLARE Pupil : Student


DECLARE NewPupil : Student
DECLARE Position : INTEGER

NewPupil.Surname ← "Johnson"
NewPupil.Firstname ← "Leroy"
NewPupil.DateOfBirth ← 02/01/2005
NewPupil.YearGroup ← 6
NewPupil.FormGroup ← ꞌAꞌ

OPENFILE StudentFile.Dat FOR RANDOM


FOR Position = ← 20 TO 10 STEP - 1
SEEK "StudentFile.Dat", Position
GETRECORD "StudentFile.Dat", Pupil
SEEK "StudentFile.Dat", Position + 1
PUTRECORD "StudentFile.Dat", Pupil
NEXT Position

SEEK "StudentFile.Dat", 10
PUTRECORD "StudentFile.Dat", NewPupil

CLOSEFILE "StudentFile.dat"

You might also like