Master Pseudocode with Pro
Get unlimited access to the AI Tutor, Code Generator, and Converters. Plus, enjoy an ad-free experience.
If Statements and Selection in Pseudocode
Programs rarely run from start to finish without needing to evaluate data or adjust their execution paths. To build dynamic applications, whether you are validating user input, triggering events in a game, or processing grades, your code needs to make decisions.
In programming, this decision-making process is called Selection. Selection constructs evaluate boolean conditions (statements that resolve to either TRUE or FALSE) and steer the flow of the program accordingly. The most common form of selection is the IF statement.
In this guide, we will explore the core concepts behind IF, ELSE, ELSE IF, and CASE structures. We'll break down the logic with generic examples before explicitly defining the syntax and rules for the AQA, OCR, and Cambridge (CIE) exam boards.
Table of Contents
Core Concepts: Making Decisions
At the heart of selection are boolean conditions. The code evaluates an expression (e.g., score > 50). If the evaluation is true, one block of code runs. Let's look at the basic building blocks of selection logic.
The Basic IF Statement
The standalone IF statement executes its nested code block only if the specified condition evaluates to true. If the condition is false, the program entirely skips the block and continues execution underneath.
Adding an ELSE Clause
Often, you want an alternative action to occur if the condition is false. The ELSE keyword acts as a catch-all. It guarantees that if the IF statement fails, the code inside the ELSE block will run instead.
Chaining with ELSE IF
When there are more than two possible outcomes, you can chain conditions together using ELSE IF. The program checks these conditions sequentially from top to bottom. As soon as one evaluates to true, it executes that block and skips the rest.
Using CASE / SWITCH Statements
If you find yourself writing a long chain of ELSE IF statements checking the exact same variable against different specific values, a CASE (or SWITCH) statement provides a much cleaner, more readable structure.
Syntax Variations by Exam Board
While the underlying branching logic remains the same, exam boards require different formatting and structural keywords. Below are the rules and syntax for AQA, OCR, and Cambridge (CIE).
AQA Pseudocode Standard
AQA uses strict capitalization for its control structures. It does not have a dedicated CASE or SWITCH keyword documented in the primary guide, meaning you should rely on nested IF chains instead.
- Keywords:
IF,THEN,ELSE IF,ELSE, andENDIF. - Operators: Uses standard equality operators like
=for checks, not==.
OCR Pseudocode Standard
OCR syntax generally prefers lowercase conventions. It combines else and if into a single elseif keyword, and utilizes switch for checking multiple fixed states.
- IF Keywords:
if/else,elseif,endif. Uses double equals==for comparison. - SWITCH Keywords: Uses
switch,case,default, andendswitch.
Cambridge (CIE / 9618) Standard
The Cambridge International standard is explicit and strict, mirroring legacy languages like Pascal.
- IF Keywords:
IF,THEN,ELSE,ENDIF. CIE syntax does not have an explicitELSE IFkeyword; instead, it relies on nesting IF statements inside ELSE blocks or using CASE. - CASE Keywords: Uses
CASE OF, lists the value with a colon, provides a catch-all withOTHERWISE, and closes withENDCASE.
Conclusion
Selection via IF and CASE statements is what brings programs to life, allowing code to evaluate data and react dynamically. Whether checking age restrictions, processing varying data types, or building complex menus, mastering these control structures is non-negotiable for a programmer.
Remember that while the boolean logic (TRUE/FALSE) evaluating the code branches is universal, your execution depends on your specification. OCR prefers the clean switch, AQA relies entirely on IF/ELSE IF chains, and CIE demands structured CASE OF blocks. Practice these variations in the editor to solidify your understanding.
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