UNIHIVE

Study Hub UNIPORT CSC 180.1

CSC 180.1 · Introduction to Computer Science and BASIC Programming

The BASIC language and program structure

What BASIC is, the programming cycle, line numbers, statements, keywords and the rules for writing BASIC programs.

Our notes

2 min read

What BASIC is

BASIC (Beginner's All-purpose Symbolic Instruction Code) was created in 1964 by John Kemeny and Thomas Kurtz at Dartmouth College for beginners. Later versions: GW-BASIC, QBasic, Visual Basic, FreeBASIC.

Languages and translators

  • Machine language: binary, understood directly by the CPU.
  • Assembly language: short codes (mnemonics), translated by an assembler.
  • High-level languages (BASIC, FORTRAN, C, Python): English-like, translated by a compiler (whole program at once into machine code) or an interpreter (line by line as it runs). Classic BASIC is usually interpreted.

Structure of a classic BASIC program

10 REM AREA OF A RECTANGLE
20 INPUT "LENGTH, WIDTH"; L, W
30 LET A = L * W
40 PRINT "AREA ="; A
50 END
With L = 5 and W = 3 it prints AREA = 15.

Rules for writing BASIC statements

  1. Each line starts with a line number (often 10, 20, 30... so lines can be inserted later). Lines run in number order.
  2. One statement per line (or several separated by colons in many dialects).
  3. Each statement starts with a keyword: REM, LET, INPUT, PRINT, READ, DATA, IF, GOTO, FOR, NEXT, GOSUB, RETURN, DIM, END, STOP.
  4. Keywords cannot be used as variable names.
  5. END is the last line.
  6. Strings are written in double quotes.

System commands (not part of the program)

RUN (execute), LIST (show the program), NEW (clear it), SAVE and LOAD (files), and in some versions EDIT, DELETE and RENUM.

Kinds of errors

  • Syntax error: breaks the language rules (PRNT, missing quote). The translator reports it.
  • Run-time error: occurs while running (division by zero, "out of DATA").
  • Logic error: the program runs but gives wrong answers (wrong formula). Found by testing and tracing.

Exams usually ask

  • What do the letters BASIC stand for? Who developed it and when?
  • State the rules for writing a BASIC program.
  • Distinguish compiler from interpreter and syntax from logic errors.

Common mistake

Writing a program with line numbers out of the intended order. BASIC sorts lines by number, so line 25 runs between 20 and 30 whatever order you typed them.

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 180.1 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.