What's changed: Initial version
1.5Pseudocode & programming
Covers how to read the IPA pseudocode used in Exam B of the FE exam: procedure declarations, variables and assignment (<-), conditional branching (if / elseif / else / endif), loops (for / while), array indexing, and how to trace code—manually executing it line by line to follow how values change.
Sixteen of Exam B's twenty questions are algorithm problems written in pseudocode. So that no specific programming language is required, IPA defines its own pseudocode notation. This section is not about writing code but about building the skill to accurately read and trace given pseudocode. Once you can read it fluently, the algorithm knowledge from the previous sections (search, sort, complexity) becomes directly usable in the actual question format.
1.5.1Basic notation: procedures, variables, and assignment
- A procedure is a named unit of processing (equivalent to a function or method in other languages). It is declared as
type: procedureName(argType: argName, ...)and returns a value withreturn. Callers invoke it asprocedureName(arguments). - A variable is declared as
type: variableName. Assignment uses the arrow symbol<-(written<-in this note), as invariableName <- expression, storing the right-hand value into the left-hand variable. Note this differs in meaning from the mathematical equals sign "=". - An array element is addressed by index, as in
A[i]. IPA pseudocode indices are 1-based (1-origin) by convention, which differs from many programming languages that use 0-based indexing—an important point to watch for.
1.5.2Conditional branching and loops
- Conditional branching takes the form
if (condition) then action1 elseif (condition2) then action2 else action3 endif. Conditions are evaluated top to bottom, and only the first branch whose condition is true executes, after which control skips toendif. - A for loop takes the form
for (i from 1 to n step 1) action endforand is used when the number of iterations is known in advance. A while loop takes the formwhile (condition) action endwhile, repeating the action only while the condition holds true (used when the iteration count is not known in advance). - Tracing means manually executing pseudocode line by line, as a computer would, writing down how each variable's value changes (often in a table). Building a value table as you go makes it much easier to catch mistakes partway through.
The most-tested basics: "<- is assignment (stores the right-hand value into the left-hand variable)", "indices start at 1", and "for is a loop with a known count, while is a condition-driven loop". Actual questions center on two patterns—fill-in-the-blank (part of the logic is blank, and you select the correct expression or condition) and tracing (asked for a variable's final value)—so practicing by writing values into a table by hand is the most effective preparation.
Let us trace the following pseudocode procedure. integer: sum(array of integer: A, integer: n) takes array A and count n, initializes a running total with integer: total <- 0, then repeats total <- total + A[i] inside for (i from 1 to n step 1) (incrementing i by 1 from 1 to n), and finally returns the sum via return total. Trace it with A = {1, 2, 3, 4, 5} and n = 5. Start with total = 0. At i = 1: total <- 0 + A[1] (=1) = 1. At i = 2: total <- 1 + A[2] (=2) = 3. At i = 3: total <- 3 + A[3] (=3) = 6. At i = 4: total <- 6 + A[4] (=4) = 10. At i = 5: total <- 10 + A[5] (=5) = 15. Once i exceeds n (=5), the loop ends, and return total returns 15. This step-by-step process of writing values into a table is exactly what tracing means—tedious as it may feel at first, always writing the values down by hand substantially cuts careless mistakes. If you rewrote this for loop using while (i <= n), forgetting to add a manual update i <- i + 1 inside the loop body would cause an infinite loop—a for loop manages the iteration count automatically, but a while loop requires you to update every variable involved in its condition yourself.
| i | A[i] | total (after update) |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 3 |
| 3 | 3 | 6 |
| 4 | 4 | 10 |
| 5 | 5 | 15 |
Trap: "IPA pseudocode array indices start at 0, like most other languages" is wrong—IPA pseudocode is 1-origin (indices start at 1) as a rule. Also wrong: "a while loop manages the iteration count automatically, just like a for loop"—a while loop only evaluates its condition; you must update the variables the condition depends on yourself, or you get an infinite loop.
1.5.3Section summary
- Assignment =
<-(right-hand side into left-hand side). Array indices are 1-origin.if/elseif/else/endifevaluates top to bottom and executes only the first true branch - for = a loop with a known count, while = a condition-driven loop (watch for infinite loops from a missed update)
- Tracing = manually executing line by line and writing values into a table. An essential skill for both fill-in-the-blank and final-value questions
Sign in to track progress — Log in.
Quick check
(just a quick review)Q1. Which statement correctly describes array indexing in IPA pseudocode?
Q2. Which statement correctly compares `for (i from 1 to n step 1)` with `while (condition)`?
Q3. A procedure `sum(A, n)` starts with `total <- 0`, repeats `total <- total + A[i]` while incrementing `i` from 1 to n by 1, and returns `total`. Given `A = {1, 2, 3, 4, 5}` and `n = 5`, what value is returned?

