User Tools

Site Tools


tutorials:basic

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:basic [2013/07/14 16:05]
irl created
tutorials:basic [2022/03/23 02:18] (current)
rcs [External Resources]
Line 1: Line 1:
- 
-====== **Under Construction** ====== 
- 
-This page is under construction by user IRL. Please don't mess with it until I've removed this message. 
- 
- --- //[[irl@twenex.org|irl]] 2013/07/14 16:04// 
- 
 ====== Using BASIC ====== ====== Using BASIC ======
  
Line 16: Line 9:
 This section will explain the fundamentals of creating a BASIC program, compiling and running it. This section will explain the fundamentals of creating a BASIC program, compiling and running it.
  
-Talk about:+BASIC programs require line numbers. You should increment each line by 10 to allow for adding lines in between later.
  
-    * Line numbers +Start by creating a file with the file extension of .B20 with the contents: 
-    Hello, World! program + 
-    * Compile process+''10 PRINT "Hello, World!"'' 
 + 
 +This is the infamous Hello, World! program for the TOPS-20 flavor of BASIC. 
 + 
 +To run the program, start the BASIC program: 
 + 
 +''@BASIC'' 
 + 
 +You will now need to load your program. At the ''READY'' prompt, type: 
 + 
 +''OLD'' 
 + 
 +You'll then be prompted for the filename of the source file you created. For instance, if you called the file ''HELLO.B20'' then that's what you should enter. 
 + 
 +At the next ''READY'' prompt, type ''RUN'' to run the program. You'll see "Hello, World!" printed on the output. 
 + 
 +In order to build the program for use without the BASIC program, type ''BUILD''. Then return to the EXEC by typing ''MON''. Assuming the program was named ''HELLO.B20'', you should now see a ''HELLO.EXE'' in the same directory. When you run this, you'll see the "Hello, World!" output as before.
  
 ===== Variables ===== ===== Variables =====
  
 +==== Assignment ====
 +
 +
 +Variable assignment in BASIC is pretty similar to every other programming language. It takes the form of:
 +
 +''VAR = VALUE'' or (optionally) ''LET VAR = VALUE''
 +
 +Variables do not need to be declared before use. Standard arithmetic operations like +, -, / and * are available for use with either number literals or variable names.
 +
 +==== Types ====
 +
 +BASIC variable types are determined by an optional suffix to the variable name. A suffix of $ indicates that the variable holds a string. A suffix of % indicates that the variable holds an integer. No suffix indicates that a variable holds a number (possibly with fractional part).
 +
 +It is important to remember that X, X$ and X% are all different variables, not just different interpretations of the same variable.
 ===== Reading Input ===== ===== Reading Input =====
  
 +Reading input from the terminal is rather simple. The function used is called ''INPUT''.
 +
 +The value read can be a number, integer or string depending upon the variable type given as a parameter.
 +
 +The "Hello, World!" program can be extended to be personalised like so:
 +
 +<code>
 +10 PRINT "Enter your name:"
 +20 INPUT X$
 +30 PRINT "Hello, " + $X + "!"
 +</code>
 +
 +This is also an example of string concatenation.
 ===== Loops ===== ===== Loops =====
  
-===== Conditionals =====+Given that every line has a line number, it can become tempting to use the GOTO function. This function gives an unconditional jump to the specified line number. This is a bad idea.
  
-===== Sample Programs =====+"The unbridled use of the go to statement has as an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress. ... The go to statement as it stands is just too primitive, it is too much an invitation to make a mess of one's program." -- Edsger Dijkstra (March 1968). "[[http://dl.acm.org/citation.cfm?doid=362929.362947|Go To Statement Considered Harmful]]". Communications of the ACM 11 (3): 147–148.
  
-//Users should feel free to add their programs to this section.//+There are three structured programming loop structures available for use in BASIC: for, while and do.
  
-===== External Resources =====+==== for loops ====
  
-  * [[http://manx.classiccmp.org/details/1,18285|the original manual]]+==== while loops ====
  
 +==== do loops ====
  
 +===== Conditionals =====
  
 +==== if statements ====
  
 +==== switch statements ====
  
  
 +===== Sample Programs =====
 +
 +//Users should feel free to add their programs to this section.//
 +
 +===== See Also =====
 +
 +  * [[tutorials:basic interpreter|Using the BASIC Interpreter]]
 +  * [[tutorials:basic advanced|Advanced BASIC Concepts]]
 +
 +===== External Resources =====
 +
 +  * [[https://livingcomputers.org/UI/UserDocs/TOPS-20-v7-1/5_BasicPlus2_Lang.pdf|TOPS-20 BASIC-PLUS-2 Language Manual]]
  
tutorials/basic.1373817941.txt.gz · Last modified: 2013/07/14 16:05 by irl