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
Dartmouth 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!
==Examples== Early versions of BASIC did not have the ability to read and write external files. To represent lists of data that would normally be read from a file, BASIC included the <code>DATA</code> keyword, which could be followed by an arbitrarily long list of elements, ending only at the limit of the line length. The <code>DATA</code> was non-executable and was skipped if encountered. <code>READ</code> commands would consume the data one by one, keeping track of its location within the complete collection of <code>DATA</code> elements in an internal pointer. In version 3, a <code>RESTORE</code> command was added to reset the pointer to the first <code>DATA</code> command in a program. In this example, "the first three data values are read into X, Y, and Z respectively. The value -1 is read into N. The next 11 values, .1 through .3, are read into the 11 elements of array B."<ref>{{cite book|title=BASIC Language Reference Mandual|date=January 1975|publisher=Interdata|pages=3β24}}</ref> <syntaxhighlight lang="basic"> 15 READ X, Y, Z 20 READ N 24 FOR I=0 TO 10 25 READ B(I) 26 NEXT I 40 DATA 4.2, 7.5, 25.1, -1, .1, .01, .001, .0001 45 DATA .2, .02, .002, .0002, .015, .025, .3, .03, .003 </syntaxhighlight> Unlike most subsequent BASICs, Dartmouth BASIC, from the Third Edition onwards, had a matrix keyword, <code>MAT</code>, which could prefix a number of other commands to operate on entire arrays of data with a single command. In this example, from the 1968 manual,<ref>[http://www.bitsavers.org/pdf/dartmouth/BASIC_4th_Edition_Jan68.pdf BASIC, 4th Edition, 1968], page 53</ref> <code>MAT INPUT V</code> is used to input a series of variables. When the user enters nothing on a line, this process ends and the total number of elements is accessed in the <code>NUM</code> pseudovariable.{{efn|Why <code>NUM</code> was not implemented as a function, like <code>LEN()</code>, is a mystery.}} The code then adds up all of the individual elements in the matrix and calculates the average. The Third Edition also added indentation, which is used here to clarify the loop structure. <syntaxhighlight lang="basic"> 5 LET S = 0 10 MAT INPUT V 20 LET N = NUM 30 IF N = 0 THEN 99 40 FOR I = 1 TO N 45 LET S = S + V(I) 50 NEXT I 60 PRINT S/N 70 GO TO 5 99 END </syntaxhighlight>
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)