BASIC

From Fox Labs Wiki
Jump to navigation Jump to search
BASIC
Major implementations

BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose high-level programming languages. The emergence of microcomputers in the 1970s led to the development of multiple dialects of BASIC, including Microsoft BASIC in 1975.

Data types and variables

Minimal versions of BASIC only support integer variables and one- or two-letter variable names. More powerful versions had floating-point arithmetic, and variables could be labelled with six or more letters. String variables are usually distinguished in many dialects by having the dollar sign $ suffixed to their name, and values were often identified by strings being delimited by double quotes " at the start and end.

Syntax

Data manipulation

Statement Description Example
LET Assigns a value (which may be the result of an expression) to a variable.
DATA Holds a list of values which are assigned sequentially using the READ command.
READ Reads a value from a DATA statement and assigns it to a variable.
RESTORE Resets the internal pointer to the first DATA statement, allowing the program to begin READing from the first value.
DIM Sets up an array.

Flow control

Statement Description Example
IF ... THEN ... {ELSE} Perform comparison and make decision which branches execution.
FOR ... TO ... {STEP} ... NEXT Repeat a block of code the specified number of times.
WHILE ... WEND

REPEAT ... UNTIL

Repeat a block of code while the specified condition is true. The condition may be evaluated before or after each iteration of the loop.
DO ... LOOP {WHILE} or {UNTIL} Repeat a block of code indefinitely or until the specified condition is true.
GOTO Jumps to a numbered or labelled line in the program.
GOSUB ... RETURN Jumps to a numbered or labelled line in the program, executes the code until a RETURN statement is encountered, on which it jumps back to the statement following the original GOSUB.
ON ... GOTO/GOSUB Chooses where to jump based on the specified condition.
DEF FN

Input and output

Statement Description Example
LIST Displays the full source code of the current program.
PRINT Displays a message on the screen or other output device.
INPUT Asks the user to enter the value of a variable. The statement may include a prompt message.
TAB

AT

Used with PRINT to set the position where the next character will be shown on the screen or printed on paper.
SPC Prints out the specified number of space characters.

Math functions

Statement Description Example
ABS Absolute value.
ATN Arc tangent.
COS Cosine.
EXP Exponent.
INT Integer part (typically floor).
LOG Natural logarithm.
RND Random number generation.
SIN Sine.
SQR Square root.
TAN Tangent.

Miscellaneous

Statement Description Example
REM Comment or REMark.
USR Transfers control to a machine language subroutine.
CALL Alternative form of USR.
TRON/TROFF Turns on or off the display of each line number as it is run.
ASM Inline assembly.