----- Introduction to BASIC |BASIC~ is one of many computer |languages~. The name BASIC is short for |B~eginner's |A~ll-purpose |S~ymbolic |I~nstruction |C~ode. Because it is one of the easiest computer languages to learn and master, BASIC has become the most popular language for the computer novice. BASIC consists of |statements~, |commands~ and |functions~. These are English words which have special meaning to the computer. BASIC |programs~ are simply many statements, commands and functions grouped together to perform a specific task. In the following chapters, new statements, commands and functions will be introduced to you one at a time. You then will be given a chance to try them out and see them in action. |The most important thing to remember is to~ |try each one out~. Don't worry about making mistakes, you won't hurt the computer's feelings. If you do make a mistake, the computer will tell you so. If this happens, just try again, a little differently the second time. Remember to press |F2~ when you are ready to continue. ----- The PRINT Statement The first thing we need to learn is how to make the computer write something on the screen. This is done with a |PRINT~ statement. The PRINT statement tells the computer to write on the screen whatever you put after the PRINT. |YOU TYPE~ THE COMPUTER PRINTS |PRINT 5~ 5 If you want the computer to write the answer to a math problem, put the problem after the PRINT. |YOU TYPE~ THE COMPUTER PRINTS |PRINT 3+2~ 5 Now try both of the above examples, by typing what is |under~ the words |YOU TYPE~ and pressing the |return~ key. Then remember to press |F2~ to continue. ----- The PRINT Statement (continued) If you want the computer to print words on the screen, you have to enclose the words in quotes (|" "~). |YOU TYPE~ THE COMPUTER PRINTS |PRINT "Whatever comes to mind."~ Whatever comes to mind. If you want the computer to print both words and the answer to a math problem, you must separate the two with either a comma (|,~) or a semi-colon (|;~). |YOU TYPE~ THE COMPUTER PRINTS |PRINT "The answer to 3+2 is";3+2~ The answer to 3+2 is 5 |PRINT "The answer to 3+2 is",3+2~ The answer to 3+2 is 5 The difference between using the comma and the semi-colon is the amount of space the computer leaves between items it prints. Now try the three examples above by typing what is under the words |YOU TYPE~. (In TI BASIC you may omit the semi-colon, but many versions require its use.) ----- Variable The next thing you need to understand is a |variable~. A variable is a symbol (usually a letter of the alphabet) that is used to represent a number. A variable can represents various values. They are extremely important when programming a computer. Here is how a variable works: In the algebraic expression |9=X+3~, |X~ is the variable. For the expression |9=X+3~ to be true, the value of |X~ must be |6~ (because |9~ and |6+3~ are equal). In the expression |SUM=A+B~, |SUM~, |A~ and |B~ are variables. |A~ and |B~ may have any values, and the variable |SUM~ is the total of those values. ----- Variable (continued) As you can see, a variable name may be more than one letter of the alphabet. In fact, it can be upto 40 |characters~. The first character of the variable must be a letter, but the next 39 can be either letters or numerals. There are many |reserved words~ that can not be used as variable names. A list of those words can be found by looking up |reserved words~ in your TI BASIC manual. Listed are invalid variable names and reasons why they are invalid. |FAT@~ - All characters must be letters or numerals, |@~ is neither. |2TALL~ - The first character must be a letter, |2~ is a numeral. |PRINT~ - |PRINT~ is a reserved word, as are all BASIC statements. It is a good idea to make variable names as descriptive as possible. If you want to write a program that averages two numbers, use the variable names |AVERAGE~, |NUM1~ and |NUM2~. This helps you to identify what the variables are used for, but it doesn't help the computer. A variable name directs the computer to a place in its memory where the value of that variable is stored. ----- LET Statement The |LET~ statement assigns an expression to a variable. In TI BASIC, the word LET is optional. The equal sign is sufficient as in the following examples: |LET A=3~ or |A=3~ In both of these statements, the value |3~ is assigned to the variable |A~. |LET SUM=A+B~ or |SUM=A+B~ Here, the sum of the variables |A~ and |B~ is assigned to the variable |SUM~. |LET K=K+1~ or |K=K+1~ In algebra the expression |K=K+1~ would be false (how can a number be equal to itself plus 1?). But in BASIC this means that the |new~ value of |K~ will be set equal to the |old~ value of |K~ plus |1~. ----- PRINT and LET Statements Until a variable has been assigned a value (by using a LET statement), it will be equal to zero. If you use a variable in a PRINT statement, the value of the variable will be PRINTed, and not the variable name. Type in the following five lines to see how the PRINT and LET statements work together. |PRINT NUM1;NUM2;SUM~ |LET NUM1=45~ |LET NUM2=5~ |SUM=NUM1+NUM2~ |PRINT "The sum of";NUM1;"and";NUM2;"is";SUM~ ----- Line numbers As you learned earlier, a program is a group of statements. In order for the computer to remember, organize and execute the statements in a program, each statement must have a |line number~. The computer performs each statement in the order of its line number. In the following statements |10~ PRINT 3+2 |20~ PRINT 3+3 |10~ and |20~ are line numbers. ----- LIST Command Typing |LIST~ and pressing return will print the program currently in memory. Type the following program and then type |LIST~ and press return. |10 PRINT 3+2~ |20 PRINT 3+3~ |30 PRINT 3+4~ |40 PRINT 3+5~ ----- LIST Command (continued) The computer normally executes the program in numerical order beginning with the lowest numbered line. If you want to put the statement |PRINT 3+1~ before line |10~, then assign it a line number less than 10. Type in the following: |10 PRINT 3+2~ |20 PRINT 3+3~ |30 PRINT 3+4~ |40 PRINT 3+5~ |5 PRINT 3+1~ Now type |LIST~ and press return. The LIST command will display the program in numerical order. Conventionally, programs are given line numbers in increments of 10. The computer will |re-number~ the lines for you if you type the word |RENUM~ and press return. Try this out and then |LIST~ the program again to see what happens. ----- RUN Command The |RUN~ command executes your program. When you typed in PRINT 3+2 earlier and pressed return, the computer executed the PRINT immediately. Now when you place a line number before a statement, the computer places that statement in its memory and waits for a RUN command to execute the program. Type in the following, type |RUN~ and press return. |10 PRINT 3+1~ |20 PRINT 3+2~ |30 PRINT 3+3~ |40 PRINT 3+4;~ |50 PRINT 3+5~ (Note that the semi-colon keeps the |8~ on the same line as the |7~.) ------- End of Lesson One This is the end of lesson one. Review the statements and commands you've covered in this lesson before going on. BASIC is an easy language to learn, but you shouldn't try to learn everything at once. Take some time to play with what you've learned before beginning lesson two. If you are using the BASIC Prof, |The PC-Prof.~ let me know who you are! Send your name |P.O. Box 26~ and address to: |Salina, Kansas~ |67402-0026~ If you like the Prof, include a contribution ($30 - $50 suggested) to help support development of additional volumes. Please copy and share the Prof. with other TI P.C. users. -----