Pseudocode: processing a file of records for insertion
A loop that reads each line, splits it into fields, trims and validates them, then builds an INSERT statement for each good row and counts accepted and rejected rows.
Understanding Pseudocode: processing a file of records for insertion in QCE Digital Solutions Unit 2
What it does: Fields from a file are text with possible extra spaces, so trim() cleans them and toInteger() converts the value so it can be range checked. The program creates the INSERT statement by joining fixed SQL text with the cleaned values, with quotes around text values. The loop takes each line from the file one at a time, so the file comes after 'in' and the line is the loop variable. Clean the data first. Splitting, trimming and converting the fields means validation checks the real values, not stray spaces. Bad rows must not reach the database. Build the INSERT inside the 'if valid' branch only.
Common mistakes: A counter must start at 0. Starting rejected at 1 means the final count is always one too high. It should be rejected ← 0. line is the whole text of the row. The separate values are in the fields array after split(), so it should be trim(fields[0]).
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 234–285) and word search (Modules 234–409).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
for each line in fileFill in the Blanks
Spot the Error
Student with a class code? Join your class →