Master Pseudocode with Pro
Get unlimited access to the AI Tutor, Code Generator, and Converters. Plus, enjoy an ad-free experience.
Loops and Iteration in Pseudocode
Imagine needing to print the numbers 1 through 100 on the screen. Writing the output command 100 separate times would be exhausting, prone to errors, and highly inefficient. This is the exact problem that Iteration (looping) solves.
Iteration allows us to instruct the computer to repeat a specific block of code multiple times. Whether you are searching through an array of data, running a continuous game engine, or prompting a user until they provide valid input, loops are an indispensable tool in your programming arsenal.
In pseudocode, iteration is divided into two major types: Definite and Indefinite. In this guide, we'll break down the concepts of FOR loops, WHILE loops, and REPEAT UNTIL loops generically, before covering the specific syntax requirements of AQA, OCR, and Cambridge (CIE).
Table of Contents
Core Concepts: Types of Iteration
Iteration simply means repeating a sequence of instructions. But how do we decide *when* the loop should stop? Based on this, loops are classified into definite and indefinite types. Let's look at them generically.
Definite Iteration (FOR Loops)
Definite iteration is used when you know exactly how many times the loop needs to run before it even starts. The standard construct for this is the FOR loop. It uses a counter variable that increments automatically on each pass until it reaches a target value.
Pre-Condition Indefinite Iteration (WHILE Loops)
Indefinite iteration is used when you do not know how many times the loop will run. A WHILE loop is a pre-condition loop: it checks the logic condition at the very start of the loop. If the condition is false immediately, the code inside the loop will never run.
Post-Condition Indefinite Iteration (REPEAT Loops)
A REPEAT UNTIL (or DO UNTIL) loop is a post-condition loop. It checks the logic condition at the very end of the loop. Because of this, it is guaranteed that the code inside the loop will execute at least once, regardless of the initial condition.
Syntax Variations by Exam Board
While the logic of definite and indefinite loops is universal, how you write them changes depending on your exam board.
AQA Pseudocode Standard
The AQA standard uses very specific closing statements that match the opening block.
- FOR Loops: Uses
FOR ... TO ...and closes withENDFOR. - WHILE Loops: Uses
WHILE ...and closes withENDWHILE. - REPEAT Loops: Uses
REPEATand closes withUNTIL <condition>.
OCR Pseudocode Standard
OCR syntax opts for lowercase keywords, and uses next instead of endfor.
- FOR Loops:
for ... to ...closed bynext <identifier>. - WHILE Loops:
while ... endwhile. - REPEAT Loops: Uses
doat the start, anduntil <condition>at the end.
Cambridge (CIE / 9618) Standard
Cambridge (CIE) standard uses uppercase keywords and allows for step increments in FOR loops.
- FOR Loops:
FOR ... <- ... TO .... Can optionally includeSTEP <increment>. Closed byNEXT <identifier>. - WHILE Loops:
WHILE ... ENDWHILE. - REPEAT Loops:
REPEAT ... UNTIL <condition>.
Conclusion
Loops are an essential tool for creating robust, efficient code. Definite iteration allows you to easily process data arrays and counter sequences via FOR loops. On the other hand, indefinite iteration (WHILE and REPEAT loops) gives your program the intelligence to dynamically react to states, inputs, and events without pre-determined limits.
When writing your exams or coursework, always make sure your loops are properly closed with the keyword appropriate to your board (ENDFOR vs NEXT) and that your loop conditions are guaranteed to eventually resolve to avoid endless infinite loops.
Ready to practice? Try our editor.
Give our pseudocode editor a go today for free - with a built-in compiler, tools to convert pseudocode to code, and project saving, PseudoEditor makes writing pseudocode easier than ever!
Start coding now