Sequential Code (College Board AP® Computer Science Principles): Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Sequential execution & expressions

How does sequential code execute?

  • Sequential execution means that action statements in a program are carried out one at a time, in the order they appear, from top to bottom

  • Each statement must complete before the next one begins

  • The execution order directly determines what the program does and what output it produces

  • Changing the order of statements can change the program's behavior entirely

  • Ordered steps must reflect the logic of the task: inputs must be collected before they are processed, and processing must happen before output is displayed

x ← 5
x ← x + 1
DISPLAY(x)
 
  • This displays 6 because the statements execute in order: assign 5, add 1, then display

Expressions

  • An expression is a combination of values, variables, and operators that is evaluated to produce a single value

  • Expression components include literals (e.g. 5), variables (e.g. score), and operators (e.g. +, *, =)

  • When a program encounters an expression, it evaluates all components according to the evaluation order (rules of precedence) and reduces them to one result

result ← 10 + 3 * 2
 
  • This evaluates to 16 because multiplication is performed before addition (standard mathematical precedence)

Code quality

What makes code high quality?

  • Code clarity means that the purpose of each section of code is easy to understand

  • Readability is improved by using meaningful variable names, consistent formatting, and logical organization

  • Following best practices makes code easier for others to read, debug, and maintain

Best practices for readable code

  • Keep each statement focused on a single action

  • Use comments to explain sections of code that are not immediately obvious

  • Organize code so that related statements are grouped together

Examiner Tips and Tricks

  • When tracing sequential code on the AP exam, work through each statement in order and update variable values as you go. Never skip ahead or assume the order does not matter. For expression evaluation, always apply mathematical precedence (multiplication and division before addition and subtraction) unless parentheses override the default order.

  • Code quality questions on the AP exam often ask you to identify which version of a program is most readable — look for meaningful variable names, appropriate use of comments, and logical organization as markers of high quality code

  • For the Create Performance Task, writing clear, readable code with meaningful variable names strengthens your written responses and makes your program easier for the reader to follow.

Worked Example

Consider the following code segment.

a ← 10
b ← a * 2
a ← 5
c ← a + b
DISPLAY(c)
 

What value is displayed when this code segment is executed?

(A) 15

(B) 25

(C) 30

(D) 35

[1]

Answer:

(B) 25 [1 mark]

  • b is assigned 20 (10 × 2) before a is reassigned to 5, so c evaluates to 5 + 20 = 25; the earlier reassignment of a does not affect the value already stored in b

Unlock more, it's free!

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

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

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.