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!
==== Unstructured BASIC ==== New BASIC programmers on a home computer might start with a simple program, perhaps using the language's PRINT statement to display a message on the screen; a well-known and often-replicated example is [[The C Programming Language|Kernighan and Ritchie]]'s [["Hello, World!" program]]: <syntaxhighlight lang="basic"> 10 PRINT "Hello, World!" 20 END </syntaxhighlight> An [[infinite loop]] could be used to fill the display with the message: <syntaxhighlight lang="basic"> 10 PRINT "Hello, World!" 20 GOTO 10 </syntaxhighlight> Note that the <code>END</code> statement is optional and has no action in most dialects of BASIC. It was not always included, as is the case in this example. This same program can be modified to print a fixed number of messages using the common <code>FOR...NEXT</code> statement: <syntaxhighlight lang="basic"> 10 LET N=10 20 FOR I=1 TO N 30 PRINT "Hello, World!" 40 NEXT I </syntaxhighlight> Most home computers BASIC versions, such as [[MSX BASIC]] and [[GW-BASIC]], supported simple data types, loop cycles, and arrays. The following example is written for GW-BASIC, but will work in most versions of BASIC with minimal changes: <syntaxhighlight lang="basic"> 10 INPUT "What is your name: "; U$ 20 PRINT "Hello "; U$ 30 INPUT "How many stars do you want: "; N 40 S$ = "" 50 FOR I = 1 TO N 60 S$ = S$ + "*" 70 NEXT I 80 PRINT S$ 90 INPUT "Do you want more stars? "; A$ 100 IF LEN(A$) = 0 THEN GOTO 90 110 A$ = LEFT$(A$, 1) 120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30 130 PRINT "Goodbye "; U$ 140 END </syntaxhighlight> The resulting dialog might resemble: What is your name: Mike Hello Mike How many stars do you want: 7 ******* Do you want more stars? yes How many stars do you want: 3 *** Do you want more stars? no Goodbye Mike The original Dartmouth Basic was unusual in having a matrix keyword, MAT.{{efn|From version 3 onwards.}} Although not implemented by most later microprocessor derivatives, it is used in this example from the 1968 manual<ref>{{Cite book|url=http://bitsavers.trailing-edge.com/pdf/dartmouth/BASIC_4th_Edition_Jan68.pdf |archive-url=https://web.archive.org/web/20140103140704/http://bitsavers.trailing-edge.com/pdf/dartmouth/BASIC_4th_Edition_Jan68.pdf |archive-date=2014-01-03 |url-status=live|title=Basic: a manual for BASIC, the elementary algebraic language designed for use with the Dartmouth Time Sharing System|last1=Kemeny|first1=John G.|last2=Kurtz|first2=Thomas E.|date=January 1968|publisher=Dartmouth College Computation Center|location=Hanover, N.H.|language=en|edition=4th|page=53}}</ref> which averages the numbers that are input: <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)