• Foundation
  • About 13 min
  • 5 practice questions

Programming languages: generations, algorithms and flowcharts

Name the five generations of programming languages, describe an algorithm, read flowchart symbols and tell syntax errors from logic errors.

If something looks wrong, please tell us.

Before a program exists, someone must work out the steps to solve a problem and write them in a language the computer can handle. This lesson covers the generations of languages, the idea of an algorithm and flowchart symbols, all of which are favourite topics in computer awareness papers.

Generations of programming languages

Five generations of languages
GenerationNameKey point
First (1GL)Machine languageBinary 0s and 1s; runs directly; very hard to write
Second (2GL)Assembly languageShort mnemonic codes such as ADD; needs an assembler
Third (3GL)High-level languagesEnglish-like; C, Java and Python are examples; need a compiler or interpreter
Fourth (4GL)Very high-level languagesSay what is wanted, not how; database query languages such as SQL are examples
Fifth (5GL)Problem-solving languagesBased on rules and constraints; used in artificial intelligence work

Each generation is easier for humans to read than the one before. Machine and assembly languages are called low-level and depend on the type of processor; high-level languages are largely independent of it.

Algorithm, pseudocode and flowchart

An algorithm is a finite, ordered list of clear steps that solves a problem and ends. Pseudocode writes those steps in plain English-like lines. A flowchart draws them as shapes joined by arrows.

Common flowchart symbols
SymbolShapeUsed for
TerminalOvalStart or stop
Input or outputParallelogramReading data or showing results
ProcessRectangleA calculation or an action
DecisionDiamondA yes or no question with two exits
Flow lineArrowDirection of the steps

Errors in programs

  • Syntax error: the rules of the language are broken, such as a misspelt keyword. The translator reports it.
  • Logic error: the program runs but gives a wrong result because the steps are wrong.
  • Runtime error: the program fails while running, for example by dividing by zero.

Finding and fixing errors is called debugging.

Worked examples

Example 1. Algorithm to find the larger of two numbers. Step 1: start. Step 2: read A and B. Step 3: if A is greater than B, print A; otherwise print B. Step 4: stop. For A = 7 and B = 12, 7 is not greater than 12, so the program prints 12.

Example 2. Flowchart for even or odd. Start (oval), input N (parallelogram), decision (diamond): is the remainder of N divided by 2 equal to 0? If yes, print Even; if no, print Odd; then stop. For N = 9 the remainder is 1, so the answer is Odd.

Example 3. Algorithm to add the first five natural numbers. Set total to 0. Repeat for counter 1 to 5: add counter to total. Totals after each step are 1, 3, 6, 10 and 15. The result is 15, which agrees with 1 + 2 + 3 + 4 + 5 = 15.

Example 4. A program to find the area of a rectangle uses the line area = length + breadth. It runs without any complaint but gives 5 for a 2 by 3 rectangle instead of 6. This is a logic error, since the syntax is correct but the formula is wrong.

An algorithm is finite, clear and ordered. A diamond asks a question; a rectangle does work; an oval starts or stops.

Key takeaways. Languages run from machine code to fifth generation, getting more human-friendly. An algorithm has finite, clear steps. Learn the flowchart shapes. Syntax errors are caught by the translator, while logic errors give wrong answers silently.

Check your understanding

  1. 1. Which generation of programming language is assembly language?

    1. First
    2. Third
    3. Fourth
    4. Second
    Show answer

    Answer: D. Machine language is the first generation and assembly language is the second. High-level languages form the third.

  2. 2. In a flowchart, a decision is drawn as a:

    1. Rectangle
    2. Diamond
    3. Oval
    4. Parallelogram
    Show answer

    Answer: B. A diamond holds a yes-or-no question with two exits. A rectangle is a process, an oval is start or stop, and a parallelogram is input or output.

  3. 3. A program that runs but prints a wrong total because of a wrong formula has a:

    1. Syntax error
    2. Hardware error
    3. Logic error
    4. Print error
    Show answer

    Answer: C. The language rules are followed, so it is not a syntax error; the steps themselves are wrong, which is a logic error.

  4. 4. For N = 9, an even-or-odd flowchart tests the remainder of N divided by 2. What is printed?

    1. Odd
    2. Even
    3. Zero
    4. Nine
    Show answer

    Answer: A. 9 divided by 2 leaves remainder 1, which is not 0, so the flowchart prints Odd.

  5. 5. Which of these is a fourth-generation (very high-level) language?

    1. Binary code
    2. Assembly
    3. Machine code
    4. SQL
    Show answer

    Answer: D. SQL describes what data is wanted rather than how to fetch it, a fourth-generation feature. Machine code and assembly are first and second generation.

Sign in to keep track of the lessons you finish.

Next lesson → Final self-assessment: software basics

Privacy · Terms · Refunds · Delivery