Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
BASIC
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Typical BASIC keywords{{Anchor|keywords}} === ==== Data manipulation ==== ; <code>LET</code> : assigns a value (which may be the result of an [[expression (programming)|expression]]) to a variable. In most dialects of BASIC, <code>LET</code> is optional, and a line with no other identifiable keyword will assume the keyword to be <code>LET</code>. ; <code>DATA</code> : holds a list of values which are assigned sequentially using the READ command. ; <code>READ</code> : reads a value from a <code>DATA</code> statement and assigns it to a variable. An internal pointer keeps track of the last <code>DATA</code> element that was read and moves it one position forward with each <code>READ</code>. Most dialects allow multiple variables as parameters, reading several values in a single operation. ; <code>RESTORE</code> : resets the internal pointer to the first <code>DATA</code> statement, allowing the program to begin <code>READ</code>ing from the first value. Many dialects allow an optional line number or ordinal value to allow the pointer to be reset to a selected location. ; <code>DIM</code> : Sets up an array. ==== Program flow control ==== ; <code>IF ... THEN ... {ELSE}</code> : used to perform comparisons or make decisions. Early dialects only allowed a line number after the <code>THEN</code>, but later versions allowed any valid statement to follow. <code>ELSE</code> was not widely supported, especially in earlier versions. ; <code>FOR ... TO ... {STEP} ... NEXT</code> : repeat a section of code a given number of times. A variable that acts as a counter, the "index", is available within the [[Control flow#Loops|loop]]. ; <code>WHILE ... WEND</code> and <code>REPEAT ... UNTIL</code> : repeat a section of code while the specified condition is true. The condition may be evaluated before each iteration of the loop, or after. Both of these commands are found mostly in later dialects. ; <code>DO ... LOOP {WHILE}</code> or <code>{UNTIL}</code> : repeat a section of code indefinitely or while/until the specified condition is true. The condition may be evaluated before each iteration of the loop, or after. Similar to <code>WHILE</code>, these keywords are mostly found in later dialects. ; <code>[[Goto|GOTO]]</code> : jumps to a numbered or labelled line in the program. Most dialects also allowed the form {{code|GO TO}}. ; <code>GOSUB ... RETURN</code> : jumps to a numbered or labelled line, executes the code it finds there until it reaches a <code>RETURN</code> command, on which it jumps back to the statement following the <code>GOSUB</code>, either after a colon, or on the next line. This is used to implement [[subroutine]]s. ; <code>ON ... GOTO/GOSUB</code> : chooses where to jump based on the specified conditions. See [[Switch statement]] for other forms. ; <code>DEF FN</code> : a pair of keywords introduced in the early 1960s to define functions. The original BASIC functions were modelled on FORTRAN single-line functions. BASIC functions were one expression with variable arguments, rather than [[subroutine]]s, with a syntax on the model of <code>DEF FND(x) = x*x</code> at the beginning of a program. Function names were originally restricted to FN, plus one letter, ''i.e.'', FNA, FNB ... ==== Input and output ==== ; <code>LIST</code> : displays the full source code of the current program. ; {{anchor|PRINT}}<code>PRINT</code> : displays a message on the screen or other output device. ; <code>INPUT</code> : asks the user to enter the value of a variable. The statement may include a prompt message. ; <code>TAB</code> : used with <code>PRINT</code> to set the position where the next character will be shown on the screen or printed on paper. <code>AT</code> is an alternative form. ; <code>SPC</code> : prints out a number of space characters. Similar in concept to <code>TAB</code> but moves by a number of additional spaces from the current column rather than moving to a specified column. ==== Mathematical functions ==== ; <code>ABS</code> : Absolute value ; <code>ATN</code> : Arctangent (result in [[radian]]s) ; <code>COS</code> : Cosine (argument in [[radian]]s) ; <code>EXP</code> : Exponential function ; <code>INT</code> : Integer part (typically [[floor function]]) ; <code>LOG</code> : Natural logarithm ; <code>RND</code> : [[Random number generation]] ; <code>SIN</code> : Sine (argument in [[radian]]s) ; <code>SQR</code> : Square root ; <code>TAN</code> : Tangent (argument in [[radian]]s) ==== Miscellaneous ==== ; <code>REM</code> : holds a programmer's comment or REMark; often used to give a title to the program and to help identify the purpose of a given section of code. ;{{anchor|USR}} <code>USR</code> ("User Serviceable Routine"): transfers program control to a [[Machine code|machine language]] subroutine, usually entered as an alphanumeric [[String (computer science)|string]] or in a list of DATA statements. ; <code>CALL</code> : alternative form of <code>USR</code> found in some dialects. Does not require an artificial parameter to complete the function-like syntax of <code>USR</code>, and has a clearly defined method of calling different routines in memory. ; <code>TRON</code> / <code>TROFF</code>: turns on display of each line number as it is run ("TRace ON"). This was useful for [[debugging]] or correcting of problems in a program. TROFF turns it back off again. ; <code>ASM</code> : some compilers such as Freebasic,<ref>{{Cite web|url=http://www.freebasic.net/wiki/wikka.php?wakka=KeyPgAsm|title=KeyPgAsm|website=FreeBasic Wiki|access-date=August 2, 2017}}</ref> Purebasic,<ref>{{Cite web|url=https://www.purebasic.com/documentation/reference/inlinedasm.html|title=Inline x86 ASM|website=Pure Basic|access-date=August 2, 2017}}</ref> and Powerbasic<ref>{{Cite web|url=https://www.powerbasic.com/help/pbcc/using_assembly-language_in_your_code.htm|title=Using assembly-language in your code|website=Power Basic|access-date=August 2, 2017|archive-url=https://web.archive.org/web/20170802164032/https://www.powerbasic.com/help/pbcc/using_assembly-language_in_your_code.htm|archive-date=August 2, 2017|url-status=dead}}</ref> also support [[Inline assembler|inline assembly]] language, allowing the programmer to intermix high-level and low-level code, typically prefixed with "ASM" or "!" statements.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)