BASIC: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{Infobox programming language}} '''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. {{Stub}}{{Programming languages}}") |
mNo edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Infobox programming language}} | {{Infobox programming language|implementations={{flatlist|class=nowraplinks | | ||
* [[Dartmouth BASIC]] | |||
* [[Tiny BASIC]] | |||
* [[Applesoft BASIC]] | |||
* [[Atari BASIC]] | |||
* [[Sinclair BASIC]] | |||
* [[Commodore BASIC]] | |||
* [[BBC BASIC]] | |||
* [[TI-BASIC]] | |||
* [[Casio BASIC]] | |||
* [[Microsoft BASIC]] | |||
* [[QB64]] | |||
* [[FreeBASIC]] | |||
* [[Liberty BASIC]] | |||
* [[PowerBASIC]] | |||
* [[QuickBASIC]] | |||
}}}} | |||
'''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. | '''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 <code>$</code> suffixed to their name, and values were often identified by strings being delimited by double quotes <code>"</code> at the start and end. | |||
== Syntax == | |||
=== Data manipulation === | |||
{| class="wikitable" | |||
!Statement | |||
!Description | |||
!Example | |||
|- | |||
|{{Rh}}|LET | |||
|Assigns a value (which may be the result of an expression) to a variable. | |||
| | |||
|- | |||
|{{Rh}}|DATA | |||
|Holds a list of values which are assigned sequentially using the READ command. | |||
| | |||
|- | |||
|{{Rh}}|READ | |||
|Reads a value from a DATA statement and assigns it to a variable. | |||
| | |||
|- | |||
|{{Rh}}|RESTORE | |||
|Resets the internal pointer to the first DATA statement, allowing the program to begin READing from the first value. | |||
| | |||
|- | |||
|{{Rh}}|DIM | |||
|Sets up an array. | |||
| | |||
|} | |||
=== Flow control === | |||
{| class="wikitable" | |||
!Statement | |||
!Description | |||
!Example | |||
|- | |||
|{{Rh}}|IF ... THEN ... {ELSE} | |||
|Perform comparison and make decision which branches execution. | |||
| | |||
|- | |||
|{{Rh}}|FOR ... TO ... {STEP} ... NEXT | |||
|Repeat a block of code the specified number of times. | |||
| | |||
|- | |||
|{{Rh}}|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. | |||
| | |||
|- | |||
|{{Rh}}|DO ... LOOP {WHILE} or {UNTIL} | |||
|Repeat a block of code indefinitely or until the specified condition is true. | |||
| | |||
|- | |||
|{{Rh}}|GOTO | |||
|Jumps to a numbered or labelled line in the program. | |||
| | |||
|- | |||
|{{Rh}}|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. | |||
| | |||
|- | |||
|{{Rh}}|ON ... GOTO/GOSUB | |||
|Chooses where to jump based on the specified condition. | |||
| | |||
|- | |||
|{{Rh}}|DEF FN | |||
| | |||
| | |||
|} | |||
=== Input and output === | |||
{| class="wikitable" | |||
!Statement | |||
!Description | |||
!Example | |||
|- | |||
|{{Rh}}|LIST | |||
|Displays the full source code of the current program. | |||
| | |||
|- | |||
|{{Rh}}|PRINT | |||
|Displays a message on the screen or other output device. | |||
| | |||
|- | |||
|{{Rh}}|INPUT | |||
|Asks the user to enter the value of a variable. The statement may include a prompt message. | |||
| | |||
|- | |||
|{{Rh}}|TAB | |||
AT | |||
|Used with PRINT to set the position where the next character will be shown on the screen or printed on paper. | |||
| | |||
|- | |||
|{{Rh}}|SPC | |||
|Prints out the specified number of space characters. | |||
| | |||
|} | |||
=== Math functions === | |||
{| class="wikitable" | |||
!Statement | |||
!Description | |||
!Example | |||
|- | |||
|{{Rh}}|ABS | |||
|Absolute value. | |||
| | |||
|- | |||
|{{Rh}}|ATN | |||
|Arc tangent. | |||
| | |||
|- | |||
|{{Rh}}|COS | |||
|Cosine. | |||
| | |||
|- | |||
|{{Rh}}|EXP | |||
|Exponent. | |||
| | |||
|- | |||
|{{Rh}}|INT | |||
|Integer part (typically floor). | |||
| | |||
|- | |||
|{{Rh}}|LOG | |||
|Natural logarithm. | |||
| | |||
|- | |||
|{{Rh}}|RND | |||
|Random number generation. | |||
| | |||
|- | |||
|{{Rh}}|SIN | |||
|Sine. | |||
| | |||
|- | |||
|{{Rh}}|SQR | |||
|Square root. | |||
| | |||
|- | |||
|{{Rh}}|TAN | |||
|Tangent. | |||
| | |||
|} | |||
=== Miscellaneous === | |||
{| class="wikitable" | |||
!Statement | |||
!Description | |||
!Example | |||
|- | |||
|{{Rh}}|REM | |||
|Comment or REMark. | |||
| | |||
|- | |||
|{{Rh}}|USR | |||
|Transfers control to a machine language subroutine. | |||
| | |||
|- | |||
|{{Rh}}|CALL | |||
|Alternative form of USR. | |||
| | |||
|- | |||
|{{Rh}}|TRON/TROFF | |||
|Turns on or off the display of each line number as it is run. | |||
| | |||
|- | |||
|{{Rh}}|ASM | |||
|Inline assembly. | |||
| | |||
|} | |||
{{Programming languages | |||
| implementations = {{flatlist|class=nowraplinks | | |||
* [[Dartmouth BASIC]] | |||
* [[Tiny BASIC]] | |||
* [[Applesoft BASIC]] | |||
* [[Atari BASIC]] | |||
* [[Sinclair BASIC]] | |||
* [[Commodore BASIC]] | |||
* [[BBC BASIC]] | |||
* [[TI-BASIC]] | |||
* [[Casio BASIC]] | |||
* [[Microsoft BASIC]] | |||
* [[QB64]] | |||
* [[FreeBASIC]] | |||
* [[Liberty BASIC]] | |||
* [[PowerBASIC]] | |||
* [[QuickBASIC]] | |||
}} | |||
}} | |||
[[Category:Programming languages]] |
Latest revision as of 02:20, 4 February 2024
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. | |
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. |