Basic Programming Concepts (AQA GCSE Computer Science)

Revision Note

James Woodhouse

Expertise

Computer Science

What is a programming concept?

  • A programming concept, also known as a construct, determines the order in which lines of code are executed
  • They control the logic and behaviour of code
  • There are three core programming constructs:
    • Sequence
    • Selection
    • Iteration

Sequence

What is sequence?

  • Sequence refers to lines of code which are run one line at a time
  • The lines of code are run in the order that they written from the first line of code to the last line of code
  • Sequence is crucial to the flow of a program, any instructions out of sequence can lead to unexpected behaviour or errors

Example

  • A simple program to ask a user to input two numbers, number two is subtracted from number one and the result is outputted
Line Python
01 print("Enter the first number")
02 Num1 = input()
03 print("Enter the second number")
04 Num2 = input()
05 Result = Num1 - Num2
06 print(Result)

  • A simple swap of line 01 and line 02 would lead to an unexpected behaviour, the user would be prompted to input information without knowing what they should enter

Selection

What is selection?

  • Selection is when the flow of a program is changed, depending on a set of conditions
  • The outcome of this condition will then determine which lines or block of code is run next
  • Selection is used for validation, calculation and making sense of a user's choices
  • if... then... else... statements are used when you test conditions sequentially

if-else-if-else-statement-pseudocode-computer-science-revision-notes

Example

Concept Pseudocode Python
IF-THEN-ELSE

IF answer == "Yes" THEN

OUTPUT("Correct")

ELSE IF answer == "No" THEN

OUTPUT("Wrong")

ELSE

OUTPUT("Error")

ENDIF

if answer == "Yes":

print("Correct")

elif answer == "No":

print("Wrong")

else:

print("Error")

Nested Selection

What is nested selection?

  • Nested means to be 'stored inside the other'
  • An example of nested selection is one IF statement inside of another
  • It is worth noting that iteration can be nested as well and this can be seen in the iteration revision note

Examples of nested selection

// Prompt the user to enter a number
PRINT "Enter a number: "
test_score ← INPUT

// Outer statement to check the test_score is above 40
IF test_score > 40 THEN

    // Inner statement to assign the result from the test
        IF test_score > 70 THEN
            result ← "Distinction"
        ELSE IF
test_score > 55 THEN
            result ← "Merit"
        ELSE IF test_score > 40 THEN
            result ← "Pass"

            
        ENDIF

ELSE
    result ← "Fail"
ENDIF

// Output the result
OUTPUT result



You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

James Woodhouse

Author: James Woodhouse

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.