UNIHIVE

Study Hub UNIPORT CSC 183

CSC 183 · Introduction to Problem Solving

Pseudocode

Writing algorithms in structured, language-free English with the keywords for sequence, selection and repetition.

Our notes

2 min read

What pseudocode is

Pseudocode describes an algorithm in plain, structured English, close to a program but not tied to any language. It ignores the fussy details of syntax so you can focus on logic, and it converts easily into Python, C or any other language.

Common keywords

PurposeKeywords
Start and endBEGIN, END
Input and outputREAD / INPUT, PRINT / DISPLAY
AssignmentSET X TO 5, or X ← 5
SelectionIF ... THEN ... ELSE ... ENDIF; CASE ... ENDCASE
RepetitionWHILE ... DO ... ENDWHILE; FOR I ← 1 TO N ... ENDFOR; REPEAT ... UNTIL

Indent the lines inside each structure so the shape is clear.

Worked example: average of N numbers

BEGIN
  READ N
  SET SUM TO 0
  FOR I ← 1 TO N
    READ X
    SUM ← SUM + X
  ENDFOR
  AVERAGE ← SUM / N
  PRINT AVERAGE
END

Trace with N = 3 and numbers 60, 75, 84: SUM = 60, 135, 219; AVERAGE = 219 / 3 = 73.

Worked example: grading

BEGIN
  READ SCORE
  IF SCORE ≥ 70 THEN GRADE ← "A"
  ELSE IF SCORE ≥ 60 THEN GRADE ← "B"
  ELSE IF SCORE ≥ 50 THEN GRADE ← "C"
  ELSE IF SCORE ≥ 45 THEN GRADE ← "D"
  ELSE IF SCORE ≥ 40 THEN GRADE ← "E"
  ELSE GRADE ← "F"
  ENDIF
  PRINT GRADE
END

Trace: 65 → B; 45 → D; 39 → F. (This is the usual Nigerian five-point scale; check your faculty's.)

WHILE and REPEAT

  • WHILE checks the condition first, so the body may run zero times.
  • REPEAT ... UNTIL checks at the end, so the body runs at least once (good for menus and input checks).

Example: keep asking until a valid score (0 to 100) is entered:
REPEAT
  READ SCORE
UNTIL SCORE ≥ 0 AND SCORE ≤ 100

Good habits

  • One action per line.
  • Meaningful names (TOTAL, not T).
  • Close every IF and loop clearly.
  • Test it by hand (a trace table: one column per variable, one row per step).

Exams usually ask

  • Write pseudocode for a problem and trace it with given data.
  • Convert a flowchart into pseudocode or the other way round.

Common mistake

Mixing in language-specific details (semicolons, brackets) or leaving out the END of a structure.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 183 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.