Library routines#

A library routine is a block of code (subroutine, procedure, function etc), often designed to handle commonly occurring problems or tasks.

Library routines are stored in a program library and given names. This allows them to be called into immediate use when needed, even from other programs. They are designed to be used frequently.

Using library routines make writing programs faster and easier as part of the work has already been done.

Integer division operators#

DIV(<identifier1>, <identifier2>)

Returns the quotient of identifier1 divided by identifier2 with the fractional part discarded.

MOD(<identifier1>, <identifier2>)

Returns the remainder of identifier1 divided by identifier2

// Example – integer division operators

// returns 3
OUTPUT "DIV(10, 3) = ", DIV(10, 3)

// returns 1
OUTPUT "MOD(10, 3) = ", MOD(10, 3)

String operations#

LENGTH(<identifier>)

Returns the integer value representing the length of string. The identifier should be of data type string.

LCASE(<identifier>)

Returns the string/character with all characters in lower case. The identifier should be of data type string or char.

UCASE(<identifier>)

Returns the string/character with all characters in upper case. The identifier should be of data type string or char.

SUBSTRING(<identifier>, <start>, <length>)

Returns a string of length length starting at position start. The identifier should be of data type string, length and start should be positive and data type integer.

Generally, a start position of 1 is the first character in the string.

// Example – string operations

// returns 10
OUTPUT LENGTH("Happy Days")

// returns 'w'
OUTPUT LCASE('W')

// returns "HAPPY"
OUTPUT UCASE("Happy")

// returns "Happy"
OUTPUT SUBSTRING("Happy Days", 1, 5)

Other library routines#

ROUND(<identifier>, <places>)

Returns the value of the identifier rounded to places number of decimal places. The identifier should be of data type real, places should be data type integer.

RANDOM()

Returns a random number between 0 and 1 inclusive

// Example – ROUND and RANDOM

// returns 6.35 (rounded)
OUTPUT ROUND(6.34567, 2)

// returns a whole number between 0 and 6
OUTPUT ROUND(RANDOM() * 6, 0)