Iteration and Selection (VCE SSCE Mathematical Methods): Revision Notes
Iteration and Selection
When writing algorithms, the order in which steps are executed is crucial. Normally, steps run sequentially, one after another. However, there are two powerful programming constructs that allow you to control this flow in different ways: iteration and selection.
Understanding iteration
Iteration is a fundamental concept in programming that allows you to repeat a set of instructions multiple times in a controlled manner. Think of it as creating a cycle of steps that keeps running until a specific condition is met.
Iteration is the backbone of efficient programming. Without loops, you would have to write the same instructions repeatedly, making code long, error-prone, and difficult to maintain. Mastering iteration is essential for solving real-world problems that involve repetitive tasks.
Key terms in iteration
A loop is the sequence of instructions that you want to repeat. Each time the loop completes one full cycle, we call this a pass of the loop. Loops are essential for performing repetitive calculations efficiently, such as processing lists of data or performing the same operation many times.
When working with loops, you'll often need to update variables. We use the arrow notation () to show variable assignment. For example, means "take the current value of , add to it, and store this new value back in ".
This is different from an equation - it's an instruction to update a variable's value, not a mathematical equality.
Worked example: compound interest calculation
Worked Example: Compound Interest Calculation
Let's see how iteration works with a practical financial example.
Problem: Sophia invests $100,000 at an interest rate of 5% per annum, compounded annually. We need to find the value of her investment at the end of each year for the first five years.
Solution:
The interest rate of 5% means we multiply by each year (since ).
We'll use two variables:
- A represents the current value of the investment
- n keeps track of how many years have passed
Algorithm steps:
Step 1: Set initial values: and
Step 2: Update the investment value and year counter: and
Step 3: Display the results: Print and Print
Step 4: Continue repeating from Step 2 while
Flowchart representation:

Table showing each pass of the loop:

Notice how the investment grows from $100,000 to $127,628.16 over five years. Each pass of the loop applies the same multiplication, demonstrating the power of iteration for repetitive calculations.
Working with sequences
The compound interest example produces a sequence of values. In mathematics, a sequence is an ordered list of numbers, where the position of each number matters. The individual numbers in a sequence are called terms. For instance, in the sequence , the first term is , the second term is , and so on.
An infinite sequence can be thought of as a function whose domain is the natural numbers. For example, the sequence of odd numbers can be defined by the function , where . The first term is , the second term is , and the pattern continues.
Worked example: summing sequence terms
Worked Example: Summing Sequence Terms
This example shows how to use iteration to calculate the sum of terms in a sequence.
Problem: Consider the sequence defined by , . Find the sum of the first five terms: .
Solution:
We need a variable called sum to keep a running total. It's crucial to start sum at 0 before adding anything to it.
Algorithm steps:
Step 1: Initialize variables: and
Step 2: Add the current term to the sum:
Step 3: Move to the next term:
Step 4: Continue repeating from Step 2 while
Step 5: Display the final result: Print
Flowchart representation:

Table tracking the accumulation:

The final output is 50, which represents . Notice how the sum accumulates gradually with each pass, and the algorithm automatically calculates for each value of from to .
Understanding selection
While iteration allows you to repeat steps, selection lets you make decisions within your algorithm. Selection uses conditional statements to determine which steps to execute based on whether certain conditions are true or false. The most common form is the "If...then...else" structure.
Selection is particularly useful when dealing with piecewise-defined functions, where different rules apply depending on the input value. This decision-making capability makes algorithms much more flexible and powerful.
Worked example: piecewise-defined function
Worked Example: Piecewise-Defined Function
Problem: Consider the function given by:
This function generates the sequence . Write an algorithm to generate the first six terms.
Solution:
We use a variable T to represent the current term of the sequence.
Algorithm steps:
Step 1: Initialize the counter:
Step 2: Determine which formula to use:
If is even, then
Otherwise
Step 3: Display the results: Print ,
Step 4: Move to the next term:
Step 5: Continue repeating from Step 2 while
Table of results:
| 1 | 4 |
| 2 | 8 |
| 3 | 6 |
| 4 | 12 |
| 5 | 8 |
| 6 | 16 |
After the 6th pass, becomes , which fails the condition , so the loop terminates.
The key feature here is the selection in Step 2, where the algorithm chooses between two different formulas based on whether is even or odd.
Worked example: Australian tax calculation
Worked Example: Australian Tax Calculation
This real-world example demonstrates how selection handles multiple conditions in a practical application.
Problem: Calculate tax based on Australian tax brackets (from a past financial year).
Tax brackets:

Solution:
Part a: Express the tax as a piecewise-defined function.
Let be the tax on an income of $A, where is a whole number:
Part b: Write an algorithm to calculate the tax.
Step 1: Input income
Step 2a: If , then
Step 2b: Else if , then
Step 2c: Else if , then
Step 2d: Else if , then
Step 2e: Else
Step 3: Print
Understanding Cascading Selection:
The "Else" instructions mean the tax is calculated only at the first stage where the condition is satisfied. For example, if the income is $70,000, the algorithm will skip Steps 2a and 2b, calculate the tax at Step 2c (since $70,000 falls in the range where ), and then proceed directly to Step 3.
This cascading structure ensures each income is taxed according to exactly one bracket, making the algorithm both efficient and accurate.
Remember!
Key Points to Remember:
- Iteration allows you to repeat steps in a controlled way using loops, where each complete cycle is called a pass
- The arrow notation () is used for variable assignment, such as , which means "update by adding 1"
- Sequences are ordered lists of numbers, and iteration is particularly useful for processing sequence terms
- Selection enables decision-making in algorithms using conditional statements like "If...then...else"
- Piecewise-defined functions require selection to determine which formula applies based on the input value
- In cascading "else if" structures, only the first matching condition is executed, making them efficient for multi-bracket calculations like tax systems