GCSE Computer Science

Component 2

2.2 Programming Fundamentals


Variables, constants, operators, inputs, outputs and assignments

  • Variable- points to a named section of memory where a value is stored. The value can change during the program’s execution.
  • Constant- points to a named section of memory where a value is stored. The value cannot change during the program’s execution.
  • Assignment— the process of storing a value in a variable / constant. Performed with the equals sign (=) when programming.
  • Operators- perform a calculation e.g. +, -, *, /, MOD, DIV.
  • Inputs- enters data into the program.
  • Outputs- displays the results of processing.

Sequence, selection and iteration

Sequence

Instructions are executed in order from top to bottom until told to stop. This is the basic way that programs work.

EXAM REFERENCE LANGUAGE print("These instructions will...") print("execute in order...") print("one after another.") print("This is sequence.")
PYTHON print("These instructions will...") print("execute in order...") print("one after another.") print("This is sequence.")
C# Console.WriteLine("These instructions will..."); Console.WriteLine("execute in order..."); Console.WriteLine("one after another."); Console.WriteLine("This is sequence.");

Selection

The program will branch to a different section depending on the result of a comparison. In simple terms — this is an IF statement. Many languages have an alternative statement called a switch statement.

EXAM REFERENCE LANGUAGE if dog == "poodle" then print("That's a cute dog.") else print("I prefer poodles.") endif
PYTHON if dog == "poodle": print("That's a cute dog.") else print("I prefer poodles.")
C# if (dog == "poodle") { Console.WriteLine("That's a cute dog."); } else { Console.WriteLine("I prefer poodles."); }

Iteration

A section of the program is repeated either a certain number of times or until a condition is no longer true. In simple terms this will be either a FOR loop or a WHILE loop.

EXAM REFERENCE LANGUAGE for i = 0 to 10 print("Hello") next i while answer != "learncomputing" answer = input("What is the password?") end while
PYTHON for i in range(0, 11): print("Hello") while answer != "learncomputing": answer = input("What is the password?")
C# for(int i = 0; i < 11; i++) { Console.WriteLine("Hello"); } while (answer != "learncomputing") { Console.WriteLine("What is the password?"); answer = Console.ReadLine(); }


Arithmetic and boolean operators

OperatorMeaning
=Assigns a variable a value
==Compares two values to see if they are equal
!=Compares two values to see if they are not equal
*Multiply
-Subtraction
+Addition
/Divide
MODGive the remainder of a division
DIVGive just the whole number part of the answer of a division
<Less than
<=Less than or equal to
>Greater than
>=Greater than or equal to

Data types

UnitData typeAlternative names
IntegerA whole number e.g. 7
Realfloat, single, double, decimalA number with a decimal point e.g. 7.4
CharactercharA single character e.g. B
StringA collection of characters e.g. "Learn Computing"
BooleanboolA special data types that can only be either True or False

Casting

The process of converting one data type to another. See below example of casting to an integer and string.

EXAM REFERENCE LANGUAGE number = input("What number would you like?") number = int(number) print("The number was " + str(number))
PYTHON number = input("What number would you like?") number = int(number) print("The number was " + str(number)))
C# Console.WriteLine("What number would you like?"); int number = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The number was " + Convert.ToString(number));