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)
' create string variable
Dim name As String
name = "bob"
' count characters and store length
Dim l As Integer
l = LEN(name)
# create string variable
name = "Bob"
# count characters and store length
l = len(name)
name = "Bob"
l = name.length
{ not specified in eduqas pseudocode reference }
// create string variable
string name = "Bob";
// count characters and store length
int l = name.Length;
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)
' do this once, at the start of your code
Randomize()
' store a random number between 0 and 10
Dim r As Integer
r = Rnd() * 10
# do this once, at the start of your code
import random
' store a random number between 0 and 10
r = random.randint(0, 10)
{ not specified in eduqas pseudocode reference }
// do this once, at the start of your code
Random rnd = new Random();
// store a random number between 0 and 10
int r = rnd.Next(0, 10);
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.
SEND "Enter your name" To DISPLAY
RECEIVE name FROM (STRING) KEYBOARD
' Prompt the user to enter some text
Dim name As String
name = InputBox("Enter your name")
# Prompt the user to enter some text
name = input("Enter your name")
{ not specified in eduqas pseudocode reference }
// Prompt the user to enter some text
Console.WriteLine("Enter your name");
string name = Console.ReadLine();
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
' Create an integer variable
Dim IntNumber as Integer
IntNumber = 1000
' Cast the integer to a string
Dim StrNumber as String
StrNumber = IntNumber.toString()
# create an integer variable
int_number = 1000
# cast the integer to a string
str_number = str(int_number)
int_number = 1000
str_number = str(1000)
{ not specified in eduqas pseudocode reference }
// create an integer variable
int intNumber = 1000;
// cast the integer to a string
string strNumber = intNumber.toString();
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
' Create a string variable containing a number
Dim StrNumber as String
StrNumber = "1000"
' Cast the string to an integer
Dim IntNumber as Integer
IntNumber = Convert.toInt32(StrNumber)
# create a string variable containing an integer
str_number = "1000"
# cast the string to an integer
int_number = int(str_number)
str_number = "1000"
int_number = int(1000)
{ not specified in eduqas pseudocode reference }
// create a string variable containing an integer
string strNumber = "1000";
// cast the string to an integer
int intNumber = int.Parse(strNumber);
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
' Create a string variable containing a real value
Dim StrNumber as String
StrNumber = "1.1234"
' Cast the string to a real
Dim DblNumber as Double
DblNumber = Convert.toDouble(StrNumber)
# Create a string variable containing a real value
str_number = "1.1234"
# Cast the string to a real
float_number = float(str_number)
str_number = "1.1234"
float_number = float(str_number)
{ not specified in eduqas pseudocode reference }
// Create a string variable containing a real value
strNumber = "1.1234";
// Cast the string to a real
floatNumber = double.Parse(strNumber);