Start with the recap, study the fully worked examples, then use the practice problems to
check your understanding of Sequence.
This page combines explanation, solved examples, and follow-up practice so you can move
from recognition to confident problem-solving in CS Thinking.
Concept Recap
Executing a series of instructions one after another in a fixed, specific order. In sequential execution, each instruction must complete before the next one begins, and the order in which statements appear determines the order in which they run.
Do this, then that, then the next thingβorder matters and each step must finish before the next.
Read the first worked example with the solution open so the structure is clear.
Try the practice problems before revealing each solution.
Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea:Each step must complete fully before the next step begins; the order determines the result.
Common stuck point:Some steps can't be reordered; others can. Understanding dependencies is key.
Sense of Study hint:When writing sequential code, think about which steps depend on results from earlier steps. If step B uses a value computed in step A, then A must come first. Trace through your sequence line by line to verify the order produces the correct result.
Common Mistakes to Watch For
Before you work through the examples, skim the mistake guide so you know which shortcuts and
sign errors to avoid.
What is the output of this sequence of instructions? SET x = 5. SET y = 3. SET z = x + y. OUTPUT z.
Answer
8
First step
1
Step 1: x is assigned 5.
Full solution
2
Step 2: y is assigned 3.
3
Step 3: z = x + y = 5 + 3 = 8. Output: 8.
A sequence executes instructions one after another in order. The order matters β changing it would change the result.
Example 2
easy
Rearrange these steps into the correct sequence for logging into a website: (A) Click 'Login'. (B) Enter password. (C) Open browser. (D) Navigate to website. (E) Enter username.Correct order for logging into a website
Example 3
easy
Two sequences differ only by order. Sequence A: SET x = 2. SET y = x. SET x = 9. OUTPUT y. Sequence B: SET x = 2. SET x = 9. SET y = x. OUTPUT y. What does each print?
Example 4
easy
Trace: SET x = 1. SET x = x + 1. SET x = x + 1. SET x = x + 1. OUTPUT x.
Example 5
medium
Trace this swap attempt: SET a = 7. SET b = 2. SET a = b. SET b = a. OUTPUT a, b. Why doesn't this swap?Broken swap: a=b overwrites original a; both print 2
Example 6
medium
Trace: SET total = 0. SET total = total + 5. SET total = total + 10. SET total = total + 3. OUTPUT total.
Example 7
medium
Trace: SET a = 2. SET b = 3. SET c = a. SET a = b. SET b = c. OUTPUT a, b.
Example 8
hard
Trace: SET a = 3. SET b = a + 2. SET a = b * 2. SET b = a - b. OUTPUT a, b.
Example 9
hard
Trace: SET x = 8. SET y = 5. SET x = x + y. SET y = x - y. SET x = x - y. OUTPUT x, y.
Example 10
hard
Trace: SET a = 1. SET b = 2. SET c = 3. SET a = b + c. SET b = a + c. SET c = a + b. OUTPUT a, b, c.
Example 11
challenge
Six instructions with dependency arrows: A; B depends on A; C depends on A; D depends on B and C; E depends on C; F depends on D and E. Each step takes 1 unit of time. (a) Give one valid sequential order. (b) If you can run independent steps in parallel, what is the minimum total time?
Example 12
easy
Show step-by-step output for: n=2; n=nβ3; n=n+1; OUTPUT n.
Example 13
medium
A recipe lists: (1) bake 30 min, (2) preheat oven, (3) mix batter. Why is order (2),(3),(1) correct rather than (1),(2),(3)?
Example 14
medium
A program reads two numbers, prints their sum, then their product. Write the sequence of 4 steps in plain pseudocode order.
Example 15
hard
A deploy script runs: build, run tests, push to prod. A junior reorders to: push, build, test. List 2 concrete failure modes.
Example 16
challenge
Given 4 statements S1β..S4β where S3β depends on S1β and S4β depends on S2β, how many valid total orderings exist?
Practice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
easy
What is the output? SET a = 10. SET b = a * 2. SET a = 0. OUTPUT b.
Example 2
easy
Trace this pseudocode: SET x = 2. SET y = x + 4. SET x = y * 2. OUTPUT x, y.
Example 3
easy
Trace in order: x=2; y=x+3; z=yΓ2. What is z?
Example 4
easy
Which runs first in 'print A; print B; print C'?
Example 5
easy
Trace: a=1; a=a+1; a=a+1. Final a?
Example 6
easy
Will this print the right area? 'print area; area = w * h'. Yes or no?
Example 7
easy
Reorder to be correct: (1) drink coffee, (2) pour coffee, (3) brew coffee. Give the order.Correct sequence: brew first (3), then pour (2), then drink (1)
Example 8
easy
Trace: s = 'ab'; s = s + 'c'; s = s + 'd'. Final s?
Example 9
easy
In a sequence of 3 statements with no loops or ifs, how many times does the middle statement run?
Example 10
easy
Does swapping the order of 'x=5' and 'print x' change the output? Yes or no.
Example 11
medium
Trace: a=3; b=a; a=10; print b. What prints?
Example 12
medium
Trace: x=4; y=xβx; x=1; print y. What prints?
Example 13
medium
Order these so the program works: (1) compute total = price * qty, (2) read qty, (3) read price. Give the correct order.Correct order: read price (3), read qty (2), compute total (1)
Example 14
medium
Trace: n=5; n=nβ2; n=nβ3; n=n/7. Final n?
Example 15
medium
Two statements: 'open file' and 'read file'. Why must open come first, and what happens if reversed?
Example 16
medium
Trace: list=[]; append 1; append 2; remove first; append 3. What is the final list?
Example 17
medium
A setup runs: connect DB; load config; start server. A bug puts 'start server' first. Why does it fail?
Example 18
medium
Trace: a=5; b=2; a=aβb; b=a+b. Final a and b?
Example 19
medium
Trace: x=8; y=3; temp=x; x=y; y=temp. Final x and y?Trace the swap: final x=3, y=8
Example 20
challenge
Trace: a=1,b=2; a=a+b; b=aβb; a=aβb. Final a and b?
Example 21
challenge
Trace: x=2; x=x+x; x=xβx; x=xβx. Final x?
Example 22
challenge
Lines: (1) total=0, (2) total=total+price, (3) read price. A developer wrote them as 1,2,3. Why is total wrong, and what is the fix?
Example 23
easy
Trace the pseudocode: SET p = 4. SET q = 7. SET p = p + q. OUTPUT p.
Example 24
easy
What is the output? SET n = 3. SET n = n * n. SET n = n + 1. OUTPUT n.
Example 25
easy
Order these steps for making a sandwich: (A) Put filling between the slices. (B) Take out two slices of bread. (C) Open the bread bag. (D) Eat the sandwich.Correct sandwich-making order: C β B β A β D
Example 26
easy
What is the output? SET a = 5. SET b = 2. SET c = a - b. SET a = c. OUTPUT a.
Example 27
medium
Using a temporary variable, write a correct swap of a and b assuming SET a = 7, SET b = 2 at the start. Then give the output of (a, b).Correct swap with temp variable: output a=2, b=7
Example 28
medium
Trace: SET x = 4. SET y = x + 2. SET z = y * x. SET x = z - y. OUTPUT x.
Example 29
medium
Two students wrote the same recipe steps in different orders. Student A: (1) preheat oven, (2) mix batter, (3) pour into pan, (4) bake. Student B: (1) mix batter, (2) pour into pan, (3) preheat oven, (4) bake. Which version is more efficient and why?
Example 30
medium
Trace: SET x = 6. SET y = 4. SET x = x * y. SET y = x / y. OUTPUT x, y.
Example 31
medium
What gets printed? SET name = "Ana". SET greeting = "Hi, " + name. SET name = "Ben". OUTPUT greeting.
Example 32
hard
A program has the steps: (1) read input, (2) validate input, (3) compute result, (4) display result. A teammate suggests moving validation after computation to save a step on valid inputs. Why is that a bad sequence?
Example 33
hard
Trace and find the bug. Intent: convert price from dollars to cents, then add 5% tax. SET price = 12. SET tax = price * 0.05. SET price = price * 100. SET total = price + tax. OUTPUT total. Is this correct?
Example 34
hard
Reorder these 5 build steps to minimize wall-clock time. (A) Compile source: 60s. (B) Download dependencies: 90s. (C) Run unit tests: 30s, needs compiled code. (D) Lint source: 20s. (E) Package artifact: 10s, needs compiled code and passed tests. Assume D and B can run in parallel with A. List a valid sequential order; then state which two steps you'd run in parallel for the speedup.
Example 35
easy
Trace: x=7; y=xβ2; z=y+1. What is z?
Example 36
easy
Trace: a=4; b=a+a; c=b+a. What is c?
Example 37
easy
Order the steps to send an email: (1) Click Send, (2) Type message, (3) Open email app, (4) Enter recipient. Give the correct order.Correct order to send an email: 3 β 4 β 2 β 1
Example 38
easy
Trace: p=3; q=p; p=p+10. What is q?
Example 39
easy
Trace: s = ''; s=s+β²gβ²; s=s+β²oβ². What is s?
Example 40
medium
Trace: x=10; y=x/2; x=xβy; OUTPUT x.
Example 41
medium
Order so that account balance prints correctly: (1) print balance, (2) deposit = 50, (3) balance = balance + deposit, (4) balance = 100. Give the order.Correct order (4,2,3,1): balance starts at 100, deposit added, then printed
Example 42
medium
Trace: a=6; b=4; a=a+b; b=aβb; OUTPUT a, b.
Example 43
medium
Trace: m=12; m=m%5; m=mβ4; OUTPUT m.
Example 44
medium
Trace: L=[1,2]; L.append(3); L.append(L[0]); OUTPUT L.
Example 45
medium
Trace: a=2; b=aβa; c=bβa; d=c+b+a; OUTPUT d.
Example 46
medium
Trace: x=5; y=10; swap (no temp): x=x+y; y=xβy; x=xβy. Final x,y?