WRITEFILE: writing a line of text
Writes the text held in the STRING variable LineOfText into the file Names.txt as one new line. Each WRITEFILE adds one more line to the file.
Understanding WRITEFILE: writing a line of text in IGCSE Computer Science Paper 2
What it does: Every WRITEFILE statement writes one line, so two statements give two lines in the file. In 0478 pseudocode the file identifier comes first, then a comma, then the variable holding the data to write. A line of text is a STRING. An INTEGER variable can only hold whole numbers. LineOfText is a variable name, so WRITEFILE writes the text stored inside it. It does not write the name itself. The assignment arrow points left (←), towards the variable receiving the value. The file identifier is a string, so it needs quote marks around it: "Names.txt".
Common mistakes: Line holds a line of text, so it must be declared as STRING, not INTEGER. It should read DECLARE Line : STRING. The program writes a line to the file, so the file must be opened FOR WRITE, not FOR READ. READ mode cannot be used with WRITEFILE.
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 489–499) and word search (Modules 479–499).
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
WRITEFILE "Names.txt", LineOfTextFill in the Blanks
Spot the Error
Student with a class code? Join your class →