This shows you the differences between two versions of the page.
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. | ||
- | |||
- | --- // | ||
- | |||
====== 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: |
- | | + | |
- | * Compile process | + | '' |
+ | |||
+ | This is the infamous | ||
+ | |||
+ | To run the program, start the BASIC program: | ||
+ | |||
+ | '' | ||
+ | |||
+ | You will now need to load your program. At the '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | You'll then be prompted for the filename of the source file you created. For instance, if you called the file '' | ||
+ | |||
+ | At the next '' | ||
+ | |||
+ | In order to build the program for use without the BASIC program, type '' | ||
===== Variables ===== | ===== Variables ===== | ||
+ | ==== Assignment ==== | ||
+ | |||
+ | |||
+ | Variable assignment in BASIC is pretty similar to every other programming language. It takes the form of: | ||
+ | |||
+ | '' | ||
+ | |||
+ | 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 '' | ||
+ | |||
+ | The value read can be a number, integer or string depending upon the variable type given as a parameter. | ||
+ | |||
+ | The " | ||
+ | |||
+ | < | ||
+ | 10 PRINT "Enter your name:" | ||
+ | 20 INPUT X$ | ||
+ | 30 PRINT " | ||
+ | </ | ||
+ | |||
+ | 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." |
- | //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:// | + | ==== 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: | ||
+ | * [[tutorials: | ||
+ | |||
+ | ===== External Resources ===== | ||
+ | |||
+ | * [[https:// | ||