BASIC: Difference between revisions

From Fox Labs Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 19: Line 19:
'''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.


{{Stub}}{{Programming languages
== Data types and variables ==
 
== 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}
|
|
|-
|{{Rh}}|FOR ... TO ... {STEP} ... NEXT
|
|
|-
|{{Rh}}|WHILE ... WEND
REPEAT ... UNTIL
|
|
|-
|{{Rh}}|DO ... LOOP {WHILE} or {UNTIL}
|
|
|-
|{{Rh}}|GOTO
|
|
|-
|{{Rh}}|GOSUB ... RETURN
|
|
|-
|{{Rh}}|ON ... GOTO/GOSUB
|
|
|-
|{{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 |
| implementations        = {{flatlist|class=nowraplinks |
* [[Dartmouth BASIC]]
* [[Dartmouth BASIC]]

Revision as of 01:31, 4 February 2024

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

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}
FOR ... TO ... {STEP} ... NEXT
WHILE ... WEND

REPEAT ... UNTIL

DO ... LOOP {WHILE} or {UNTIL}
GOTO
GOSUB ... RETURN
ON ... GOTO/GOSUB
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.