Categories: All Variables and Constants  String manipulation  Builtin functions  Input and output  Arrays  Conditional logic  Repetition / Iteration  Functions / Procedures 

Show:

This resource is designed as a quick revision guide and must not be used by students during a NEA where internet access is not allowed. It has not been endorsed by any exam boards. If you spot any mistakes, please let me know and I'll fix them asap.

Builtin functions

A function is a named section of code that works something out and returns a value that can be used elsewhere in the code.

Builtin functions are tools within a programming language that you don't have to write from scratch: they just work out of the box.

Top tips:

  • There are loads more builtin functions for VB.NET and python than the ones listed here. 
    This website only shows the builtin functions defined in pseudocode. 
Length of a string
    

A string is some text such as "Hello"

The length of a string means how many characters (including spaces, numbers and punctuation) there are in that string

This example createa a string called name and sets it to "Bob". It counts how many characters are in that string and stores the answer (3) into a variable called l

STRING name SET name TO "Bob" INT l SET l TO LENGTH(name)
Dim name As String name = "bob" Dim l As Integer l = LEN(name)
name = "Bob" l = len(name)
name = "Bob" l = name.length
{ not specified in eduqas pseudocode reference }
Choose a random number
   

Computers can't think for themselves - they can only follow instructions., so getting them to choose a number that is truely random is not easy. Thankfully, most programming languages have a function that will choose a number for you that appears to be chosen at random.

This example generates a random integer between 0 and 10 and saves it into a variable called r

INTEGER r SET r TO RANDOM(10)
Dim r As Integer Randomize() r = Rnd() * 10
import random r = random.randint(0, 10)
// not defined in pseudocode spec so this should never come up in an exam // this is just a guess r = random(0, 10)
{ not specified in eduqas pseudocode reference }
Displaying text
    

Most programs need to output text to the user. 

This example displays the text "Hello" to the screen

SEND "Hello" TO DISPLAY
MsgBox("Hello")
print("Hello")
print("Hello")
output "Hello"
Get user input
    

Most programs need to get the user to type in data that controls how the program behaves.

This program asks the user for their name and saves the result into a string variable called name.

RECEIVE name FROM (STRING) KEYBOARD
Dim name As String name = InputBox()
name = input()
name = input()
{ not specified in eduqas pseudocode reference }
Casting (converting) to a string
     

Often it's useful to convert a number (integer or real data type) to text (string data type) so that it can be processed or sent as an output later in the program.

This example converts the integer number 1000 to a string containing "1000"

INTEGER int_number = 1000 ' There's not explicit casting. ' It's done implicitly by the data types of the variables STRING str_number = int_number
Dim IntNumber as Integer IntNumber = 1000 Dim StrNumber as String StrNumber = IntNumber.toString()
int_number = 1000 str_number = str(1000)
int_number = 1000 str_number = str(1000)
{ not specified in eduqas pseudocode reference }
Casting (converting) to an integer
     

Often it's useful to round a decimal number (real data type) to a whole number (integer data type).

It can also be useful to convert a string representation of a number (e.g. one typed in by the user) to an integer

This example converts the string "1000" to the integer 1000

STRING str_number = "1000" ' There's not explicit casting. ' It's done implicitly by the data types of the variables INTEGER int_number = str_number
Dim StrNumber as String StrNumber = "1000" Dim IntNumber as Integer IntNumber = Convert.toInt32(StrNumber)
str_number = "1000" int_number = int(1000)
str_number = "1000" int_number = int(1000)
{ not specified in eduqas pseudocode reference }
Casting (converting) to a real
     

Often it's useful to convert a string representation of a number (e.g. one typed in by the user) to a decimal number for use in calculations (real data type)

This example converts the string "1.1234" to the real value 1.1234

STRING str_number = "1.1234" ' There's not explicit casting. ' It's done implicitly by the data types of the variables REAL real_number = str_number
Dim StrNumber as String StrNumber = "1.1234" Dim DblNumber as Double DblNumber = Convert.toDouble(StrNumber)
str_number = "1.1234" float_number = float(str_number)
str_number = "1.1234" float_number = float(str_number)
{ not specified in eduqas pseudocode reference }

Loading...