CSC 180.1 · Introduction to Computer Science and BASIC Programming
Our notes
1 min readConstants
- Numeric: 25, −3.5, 1.2E3 (= 1,200), 4E−2 (= 0.04).
- String: characters in quotes: "UNIPORT", "NAME".
Variables (symbolic names)
A variable is a named memory location whose value can change.
- Numeric variables: a letter, or a letter followed by letters or digits: A, X1, SUM, TOTAL.
- String variables: end with $: N$, NAME$.
- Classic BASIC allowed only one letter or a letter and a digit; newer dialects allow longer names. Names must not be keywords and must not start with a digit.
Assignment: LET
LET X = 5 stores 5 in X. LET is optional in most dialects (X = 5). It is not an equation: X = X + 1 means "add 1 to the old value of X".
Arithmetic operators and precedence
| Order | Operator | Meaning |
|---|---|---|
| 1 | ( ) | brackets first |
| 2 | ^ | power |
| 3 | − (unary) | negation |
| 4 | * / | multiply, divide (left to right) |
| 5 | \ and MOD | integer division, remainder (QBasic) |
| 6 | + − | add, subtract (left to right) |
Worked examples
- 2 + 3 * 4 ^ 2 = 2 + 3 * 16 = 2 + 48 = 50.
- (2 + 3) * 4 ^ 2 = 5 * 16 = 80.
- 20 / 4 * 5 = 5 * 5 = 25 (left to right, not 20/20).
- 17 MOD 5 = 2; 17 \ 5 = 3.
Writing formulas in BASIC
| Mathematics | BASIC |
|---|---|
| ax² + bx + c | A*X^2 + B*X + C |
| (a + b)/(c − d) | (A+B)/(C−D) |
| √(b² − 4ac) | SQR(B^2 − 4*A*C) |
| x³/(2y) | X^3/(2*Y) |
| πr² | 3.14159*R^2 |
The multiplication sign must always be written: 2X must be 2*X.
Relational and logical operators
=, <>, <, >, <=, >= compare values; AND, OR, NOT combine conditions: IF S >= 40 AND S < 50 THEN PRINT "D".
String operations
+ joins strings: "UNI" + "PORT" = "UNIPORT". Functions such as LEN, LEFT$, RIGHT$, MID$ work on strings.
Exams usually ask
- State which variable names are valid and which are not (and why).
- Evaluate BASIC expressions using precedence.
- Write mathematical formulas as BASIC expressions.
Common mistake
Writing X/2*Y for x/(2y). It means (x/2)·y. Use brackets: X/(2*Y).
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick Variable (high-level programming language)
(opens en.wikipedia.org in a new tab)
Wikipedia, Variable (high-level programming language), CC BY-SA 4.0 · licence
-
Constant (computer programming)
(opens en.wikipedia.org in a new tab)
Wikipedia, Constant (computer programming), CC BY-SA 4.0 · licence
-
Order of operations
(opens en.wikipedia.org in a new tab)
Wikipedia, Order of operations, CC BY-SA 4.0 · licence
-
NOUN CIT 132: Programming in BASIC
NOUN course book (PDF, about 0.8 MB). The whole BASIC programming course.
(opens nou.edu.ng in a new tab)
Watch
-
QB64 Basic programming tutorial
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
QB64 Tutorial 3 - Variables and Data Types
11 min · ≈ 50 MB · about ₦28
(opens youtube.com in a new tab)
-
QBasic Tutorial 4 - Variables And Data Types - QB64
6 min · ≈ 27 MB · about ₦15
(opens youtube.com in a new tab)
-
Coding Basics: Variables | Programming for Beginners |
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
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.