@L}5 _$% l0$)$$Hȱ$ UhL" `e$$%`$%`  R@P!( L(1   Y I`  d  Ld M * @  $ % CC$$)%1 Udߥ$9%: !0 S$% DD˙`  }J)Lr d M * @  $ % CC$$)%1 Udߥ$9%: !0 S$%} DD˙`  }J)Lr J  ((  p L ()   J}L= ( L 0q A    IB JC;? D W } LL  ` W )LA!  ߰")-݆ p" } $G@LL 08`Q")<2Q0 -G$Ș݆ UL# ; p8(()(0ʥ)NQ` }$GȘ݆LU )L ݆ L GȘ ݆LL )W>Z   HH)H }p h  hyhy D L> L JJ    ! LA*` BF }7'8  M HN H` 8 Z  \LdJJ!"! GFE@F (!L }EE !E^ ^ E E7EȩEdE/EȩE  D } .L }  ;F d  ;?F7F? ( .   Z D LL d } . D  L    p  E` , d)  D L) 0BM݊L݉} ML  N݆ L NLML [ TEqEHȱEqEh 0Gȹ G} HLL GɛL  LFREE SECTORS G) *Gȩ GȽG GȌ*jj >G} C8jJ3j2CD( C202C ԠBX` N 1? l LlD:RAMDISK}.COMLu L1 L ;LHL  T`  `8  ɐ     `TU  } L ? .  t`GBJ ~DEHI B V0dV!}QDEHI VF9 ,0 ,0 s0hhL  L` H hDHEh"}DEL8HI4 0 HI,0 0  9 .G VLO#},0 L4*IJ`llD1:AUTORUN.SYSNEED MEM.SAV TO LOAD THIS FILE.D8:MEM.SAV J y08 B|DEHI$} V0 0`B;DEL`?<0LV`@ʆ v s? F0Ξ05: [ BDEHI%} VY8 B V  @  /DE `E:D8:DUP.SYSERROR-SAVING USER MEMORY ON DISKTYPE Y TO &}STILL RUN DOS B;DE J  (` 9 V⪍ ઍ  -'}LLu ÝDEHILV 9 .l 9 .l  `` s$B BH(}I|DE V BLV nB,DE JLV B V BLVDEIʩ BꭝL 3u } 3E:}DISK OPERATING SYSTEM II VERSION COPYRIGHT 1984 ATARI CORP.A. DISK DIRECTORY I. FORMAT DISKB. RUN CARTRIDG*}E J. DUPLICATE DISKC. COPY FILE K. BINARY SAVED. DELETE FILE(S) L. BINARY LOADE. RENAME FILE M. RUN AT ADDRES+}SF. LOCK FILE N. CREATE MEM.SAVG. UNLOCK FILE O. DUPLICATE FILEH. WRITE DOS FILES P. FORMAT SINGLEL !N',}#"&))9(&*)/h)''-&؆莟R'S  vL/ˢ L }Insert DOS 2.0s, type Y Λx -}DEfHI 1莏#q! @ y0ɛ8A0,' ȅ 1 1ild! 1L!NO SUCH ITEMSELECT.} ITEM OR FOR MENU! 0 .z:*{}.|{ 1 0 0JB 18L%|DL/}%DIRECTORY--SEARCH SPEC,LIST FILE?[# 0 0 &|D3" 1L!NOT A DISK FILEN !B 1L!E# 1 !BD0}ED:}:1BJ|DE 1DEBHI 1 h0ߢ 0.1}  0?詛 1 y0YЛ 1 ;#L" ;#L! BL1TYPE "Y" TO DELETE...DELETE FILE SPEC2}COPY--FROM, TO?OPTION NOT ALLOWED697 FREE SECTORS COPYING---D8:COPY32.COMl# 0|D .L/%#3}##JB|DE 1BHID#E 1#0: B 1L!#͑### B 1#c$0SY4}S1}:## # # .#Ƚ# # 𩛙## 1,#PD#ELJ- <.BJD#E 5}1 1HH 0hh|DL%1}:̳# L% #D#EL% 1 0 . .0O% 1L!WILD CARDS NOT A6}LLOWED IN DESTINATION 0 <.|K}N 2 FORMAT. t* 5) 1L!`) 0NΞ 0 L1) 1 L!BAD LOAD FILELOAD FROM WHAT FILE?) 0 ?}0#B 1L!WHAT FILE TO LOCK?) 0 0$B 1L!WHAT FILE TO UNLOCK?DUP DISK-SOURCE,DEST DRIVES?TYPE "Y" IF OK TO US@}E PROGRAM AREACAUTION: A "Y" INVALIDATES MEM.SAV.FE! +L1   `*  70 2 2A} 0.* 1 y0 0)INSERT BOTH DISKS, TYPE RETURN^, 1 y038逍 N, 1L! ,B}C, t*  Lx+, 0 ^, 1 y0 , ,0,0 ,L+ ,I0 ,Vǭ0C}Ξ, 0 }, 1 y0C,ШC, 0K'!" H H 'h h Lx+!EF 5L1L!D,I,HhD}` NOT ENOUGH ROOMINSERT SOURCE DISK,TYPE RETURNINSERT DESTINATION DISK,TYPE RETURNE}`  `8 rL1`-* 1P* 1 y0Y`hhL!NAME OF FILE TO MOVE?- 0 0|DL% <.F},^ 1 70 0 .@L# .BJ 1  DEHIB V L1 ,} 1 70,L.  G}JB|,#P#DE 1 HI BDEHHII 1 B 1 ,^ 1 70,0La- B V,#PH},^ 1 70 0L#L!-* 1P* 1 y0Yj383}mm ݭI}}`8}``|* ? ɛ,`|:-)| / 1L!`DESTINATION CANT BE DOJ}S.SYS0 0H{ 24Δ 28/L!/) 2 Π 2 0 ξK}hAΞB,0 J 1 BDEHI,HÝDE 1HIHIDELSAVE-GIVE L}FILE,START,END(,INIT,RUN)O S0 1`BDEPHI V` S0H 1 L!M}0 0 1L~0`PLEASE TYPE 1 LETTER,0`hhL! 70 1L0L<1 ,;ɛ7,"ɛ:ݦ1ݥN}A"D|ݤD|ȩ:|ȩ|ɛ,,(/+.ީ1 1,ɛ`轤{NAMEO} TOO LONG B VL!` L1I H1EΝDL1|mDiE` V0`8d/8 i:222 1 LP}!ERROR- 164ɛ+,' 20*.. өr2 1``2TOO MANY DIGITSINVALID HEXAQ}DECIMAL PARAMETER800 0 8 00`,0'D800 H,ɛh`2L1NEED D1 THRU D8uR} ECIMAL PARAMETER800 0 8 00`,0'D800 H,ɛh`2L1NEED D1 THRU D8u05  15 2 2151^116115ύ011$r2ԭ5 3)5)5ԭx GT}@@L00)+& 2 L0=ɛ -L!1LV1L1 /3 3ȹ441L-4 v3 25 2H 2h͔5U}L3L3 2 k3U hh`DOC`QL3P1Lk0S1H /3h0B k3@ VL0LU!#$53 1181118V}1111Ε5 1Lk0552 1Ȍ1i111i11115Lk0pppB4f5&&&&&&&&^6f^6&&&&&W}&&A1@BJ D2ELVK@BHILV^Щ6 2BD2EJ VBD5EHI0 V0%5X}5 2iХiL[2 25 25`D:*.*` i@`8 ``@i `8@`0 BLV525<4Y}5`HH i ԍΗ552 ԍhh@ Lح1Э1Ѣ 24.4 24Z}4`D4E` 2BJ k3LVRH` 2BD4EhK)I JLV333> A few REMS can help a lot next year, when you try and figure out how last year's program works, to modify it.}-------------------3. PRINT STATEMENT:------------------- This statement allows you to print ON THE SCREEN of your moni}tor or TV. For example: 10 PRINT "HELLO" It will print HELLO on your screen. You can skip lines with blank print s}tatements as: 10 PRINT "HELLO" 20 PRINT 30 PRINT 40 PRINT "THERE" This prints HELLO, skips two lines }and prints THERE. Note that anything in quotes in a PRINT statement, is printed EXACTLY on the screen, blanks included. You} can print literals in quotes, or print the values of variables (next lesson.) If you put a comma between items in a PRIN}T statement, it will skip to the next print zone. There are 10 spaces in an Atari print zone. Example: 10 PRINT }"HI","THERE" This will print HI, space over 8 spaces and print THERE. The spaces per "print zone" are controllable by POK}Eing 201 with 3 to 255 (more on that later). Watch this: 10 PRINT ,,"HI" This skips over to 20, then prints HI. Com}mas will come in handy for putting things in columns for printout, and printing tables. If you put a semicolon between it}ems in a PRINT statement (normal), it doesn't skip any spaces. 10 PRINT "HI";"THERE" This prints HITHERE. A key fea}ture is a trailing semicolon (left at the end of a line). This suppresses a carriage return. Don't panic. This just means t}he printer "sits there" waiting at the end of a line like this: 10 PRINT "HI"; 20 PRINT "THERE" This prints HIT}HERE. See, the printer "waited" at the end of HI. USUALLY items in a PRINT statement are separated by semicolons, like:} 10 PRINT "HI ";"THERE ";"JOE" This prints HI THERE JOE. Note I left trailing spaces after the I and E, inside the pa}renthesis. You can use leading spaces when you wish to begin printing less than 10 spaces in. 10 PRINT " This is i}ndented" Without a trailing semicolon, every time a program sees PRINT, it skips to a new line. You can print on a pri}nter, following these same rules, but using the LPRINT statement (for line printer.) 10 LPRINT "Hello There" This }will print on the printer, but not on the screen.---------------------------------4. MULTIPLE STATEMENTS ON A LINE:------}--------------------------- More than one BASIC instruction may be placed on one line, and always is in fact, in advanced} programs. To do this, you separate statements with a colon. 10 PRINT "HI":PRINT:PRINT "JOE" This prints HI, skips} a line and prints JOE. One exception! NOTHING may follow a REM. Here's an okay example: 10 X = X + 1:REM increments} X Here's a "NOT" OKAY example: ********************************** 10 REM increment X:X = X + 1 ****************}****************** This won't work, as NOTHING past a REM statement gets executed.-------5. NEW:------- The comman}d NEW, clears out the Random Access Memory. When you're ready to write a program, you type NEW and hit the RETURN key. That }wipes all your RAM memory clean. It erases any old programs and variables, you were using. It will not affect programs s}tored on disk or tape. When you LOAD in a program from disk (see 12. LOADING A PROGRAM:), it automatically clears RAM first}, just as if it had a NEW command built-in.---------------------6. WRITING A PROGRAM:--------------------- Now we are }ready to write a program. For now, you may type in LAB 1, EXACTLY as it appears at the end of this lesson. After each line, }hit RETURN. BASIC will let you know immediately if you have any errors. If so, simply retype the line. Each new line will R}EPLACE any old line, having the same line number. Instant correction.----------7. LISTING---------- You can LIST your} code on the screen at any time, by typing LIST and RETURN or L. and RETURN. Individual lines may be listed as: L.40 } ...to list line 40. Ranges of lines may be listed by: L.10,120 ...to list lines 10 through 120 in a block. You may} stop and start the lines scrolling up off your screen during listing, by alternate presses of CONTROL+1. This means hold }down the CONTROL key while pressing the 1 key. Lines may be entered into programs out of sequence. Listing will always lis}t then in sequence. You can Clear your screen with CONTROL+CLEAR. Clearing and relisting is done every few minutes when w}riting in BASIC, so you can see the lines in sequence, and watch the program flow. You can copy lines easily, by listing }a line, then using cursor control arrows, placing your cursor on top of the existing line number, changing it and hitting R}ETURN. The original line, AND the identical line with the new number will both be present. This also allows manual renumber}ing of lines in a program. Source code may be listed to your printer in two ways. You may use: LIST "P:" or LIST} "P:",10,120 Another option is to COPY the program from disk to the printer, by going to DOS and selecting COPY. When ask}ed, copy from D1:FILENAME to P: for the printer, or S: for the screen or E: for the screen also. Printouts are very hand}y, as you can quit for the night, but study the listed printout for bugs, and areas to improve.----------------8. LINE ED}ITING:---------------- If you discover a boo-boo in a line, you can edit it. Type L. followed by the line #, or LIST fol}lowed by the line # as: L. 35 This will list that line 35 on your screen. Using your control and arrow keys, put yo}ur cursor on the line, and retype, delete, insert (using CONTROL+DELETE or INSERT) etc, to correct the line. Monkey around a}nd try it. When you change a line, the rule is that you must hit RETURN with the cursor IN that line, to save your chang}es. Experiment with it. It's great. SHIFT+INSERT and SHIFT+DELETE work on entire lines. Try them. To get rid of a line yo}u don't want, simply type the number of the line followed by RETURN. It wipes it out. Try it. That's deleting lines. T}he Atari has a screen editor, that will let you edit any lines on the screen. For the novice, this can get you in trouble so} fast, that you screw up a whole screen full of lines at once. SAVE often when editing, and only edit one line at a time }to begin. For screen editing, you must hit return with your cursor still in a line to save changes.--------------------9}. TO RUN A PROGRAM:-------------------- When you have a program typed in correctly, LIST it, and make sure it's right. T}ype RUN (no line number) and RETURN.Your program should begin executing, and produce output. It's STILL in memory, and yo}u can LIST it, or RUN it again. You can usually stop a program with the BREAK key. The RUN command is used in IMMEDIATE M}ode (no line number). When we use line numbers, we're in PROGRAMMING Mode. When we type commands in IMMEDIATE mode, we're }talking directly to the computer. You can print in immediate mode. Try: PRINT "ZOWIE" It prints, but it's also gone}, and not in memory. Try a LIST, and you'll notice it's not there.---------------------10. SAVING A PROGRAM:------------}---------DISK DRIVE: To save a program to disk, you think up an eight letter filename. It has to start with a letter, a}nd can only be eight characters (letters and numbers). No spaces are allowed. If you wish, you can type a period, and add a} three letter extension to label programs. It's usually used that way. For example GAME.BAS would be a game in BASIC. T}o save a program, type in a statement in the form that follows. The D refers to disk drive. If you use only D, it assumes D}1 or drive #1. Use the proper number if you have multiple drives. SAVE "D:FILENAME" and hit RETURN. Your disk should s}pin, and save the program under the name you gave it. Think up good names, 'cause when you have hundreds of programs, you ne}ed to be able to identify them from their name alone. At this point the program is STILL in memory, AND a copy stored on }the disk. You could remove the disk, and shut down the system, and your program will remain on the disk.CASSETTE: You }must use an Atari tape recorder to save programs. Model 410 recorders are very inexpensive, and often available for loan fro}m friends who have moved up to disk drives. Model 1010 recorders are newer. I would not consider buying a recorder new, but} save my money toward a disk drive. To SAVE a program to cassette, rewind the tape to the beginning, or the place you wa}nt to record at. Type CSAVE and RETURN in Immediate mode. You will hear two beeps, to remind you to push two keys. Push dow}n both the PLAY and RECORD buttons at the same time on the recorder. Now push RETURN again, to start the recording. When }your program has been saved to tape, the tape will stop turning. Note the counter number for future reference. No filenames} are possible with tapes.--------------11. DIRECTORY:-------------- To see a list of the files on your disk, you must }go to DOS (Disk Operating System.) This is done by typing: DOS This is in immediate mode. When you get to the DOS m}enu, follow your DOS's instructions to look at your files. When finished, return to your BASIC cartridge, usually menu opti}on B. If you are using a MEM.SAV file, your BASIC program will remain unchanged in memory. Without, when you return from }DOS, your BASIC program will be gone into never never land, and lost. This is no problem if you remember to SAVE it before }going to DOS. You can load it back in. You'll learn quickly after losing a few programs that you hadn't saved yet. Read your} disk manual about this.----------------------12. LOADING A PROGRAM:----------------------DISK DRIVE: To get that p}rogram back the next time you use your computer, install BASIC, turn on the disk drive, and printer. Insert the disk. Turn o}n computer. The disk should spin and give you READY prompt. You're in BASIC. To get back your old program, type: LOAD "}D:FILENAME" Your disk should spin, load in the program, and say "READY". To see it, type L. or LIST. To run it, type RUN.} To stop it, usually the BREAK key will do it. You can start again with RUN, or sometimes by typing CONT for continue. I}f you change your program, with line editing, or by adding to it, be sure to save a copy with the changes. I save my program} often while writing, in case I screw it up totally, or there's a (GASP) power failure. Programs saved on disk survive.CA}SSETTE: To load from cassette, wind/rewind tape to beginning of program using counter. Type CLOAD and RETURN. You will he}ar one beep. Push down the PLAY key on the recorder. Now hit RETURN once again. The tape should beginning turning, and loa}d in the program. Be patient, tape is a very slow process. You will hear bleeps as the tape loads in. Sooner or later, t}he tape will finish loading. Type LIST or RUN. Do not be alarmed if your program failed to load accurately. Simply rewind, a}nd try again. Tape loads correctly most of the time. Keep your heads clean, and if all else fails, have your local hardware} whiz realign your head. Tape is fussy.----------------SAMPLE Problems:----------------PROBLEM 0 (Can be filenamed PR}OB0) Okay here we put it all together. Type in the following program EXACTLY as it appears below.10 REM *** PROB0 ***2}0 REM Your Name - Date30 REM40 PRINT CHR$(125)50 PRINT "HELLO WORLD"60 PRINT:PRINT:PRINT70 PRINT "I am communicating wi}th the world."80 PRINT90 PRINT " by Your Name"100 END We introduced one new concept here. The PRINT CHR$(125). I}t "prints" the screen clear (clears the screen.) Handy statement to put up front in a program. Starts you off with a fresh }screen. Type the program in. Save it to disk with SAVE "D1:PROB0". When it's done and a copy saved on the disk, run it by} typing RUN. You should see output as follows:HELLO WORLDI am communicating with the world. by Your Name Try} turning your computer off, rebooting, and loading this program back in. LIST it to see if it's there. Try running it again.} If it works, then congratulate yourself. You have written a BASIC program. This program is for your own use. Do not uplo}ad this program to the BBS.------------------------------------PROB1 Write a program to produce the following output:} ************* * * * * * * * * * * * * * * * * * } * ******* * * * * * * * * * * * * * * * *************-----}-------------------------------PROB1A Write a program to print: A TTTTT A RRRR I A A T A A} R R I A A T A A R R I AAAAA T AAAAA RRRR I A A T A A R R I A A T} A A R R I------------------------------------ This concludes Lesson 1 of Learning to program in Atari BASIC. B}e sure to catch Lesson 2, which covers: LET statement Numeric variables String variables READ statement DATA} statement Math rules END statement INPUT statement We'll begin problem solving at the end of Lesson 2.Contact  }me at: Jackson Beebe Prairie Data Fields 807 W. Hill Street Urbana, IL 61801  } bye: Jackson Beebe Prairie Data Fields 807 W. Hill Street Urbana, IL 61801 TEXT&00--------------------------------------------------LESSON 2: Variables, Reading data, Input, and Math------------- }-------------------------------------(C) COPYRIGHT 1986 by Jackson Beebe This lesson is placed in the Public Domain. Ind }ividuals, user groups and BBS's may reprint, copy, show or distribute it, as long as this notice remains intact with the le}sson.---------CONTENTS:--------- NUMERIC variables STRING variables LET statement Math rules IN}PUT statement READ statement DATA statement RESTORE statement END statement This is Lesson #2 of Learn}ing to program in Atari BASIC, brought to you by Jackson Beebe. Contact me at the address at the end of the lesson.------}---FEEDBACK:--------- Since Lesson 1, I have received inquiries about what Disk Operating System (DOS) I am using. I a}m writing for Atari DOS 2.0s/2.5, as everyone with an Atari has, or has access to this DOS. Other DOS's allow variable name}s beginning with #'s, and other features. More discussion of DOS in later lessons.----------VARIABLES:---------- Tw}o common ways of using numbers in programs, are to use them as CONSTANTS, or in VARIABLES. When you simply use a number like} 3, that's a CONSTANT, because it's just and always 3. It doesn't change. VARIABLES can hold different numbers or letters} at different times in a program. For example, a payroll program, could use the variables EMPLOYEE$, RATE, HOURS, and SALAR}Y. These would hold new data each time they calculated an employee's salary. There are two kinds of variables. 1. Nu}meric Variables (numbers) 2. String Variables (letters) Numeric variable names must start with a letter, and may c}ontain up to eight uppercase letters or numbers (alphanumeric data.) No spaces are allowed. As a general rule, you should k}eep variable names short, but use names that suggest what they do. For example to set up a numeric variable to hold Fahre}nheit temperature in a conversion program, you could call it FAHREN, FTEMP, F, etc. String variables hold letters, or wor}ds, sentences, etc. They must begin with a letter, and end in a dollar sign, as NAME$. A quirk of Atari BASIC requires th}at string variables be dimensioned before use. This is done with the DIM statement followed by the variable name, and the m}aximum length the computer should reserve storage for. For example: 10 DIM NAME$(20) This reserves storage for a }name of up to 20 characters in length. If you typed 25 letters for input, it would only read 20. If you forget, you'll ge }t an error message when you try and use a string variable you haven't dimensioned. More than one variable may be dimensioned!} by separating variable names with commas. For example:10 DIM ADDR$(20),CITY$(20),STATE$(2)--------------LET STATEME"}NT:-------------- The LET statement, assigns something to a variable. It could set X = 0, or NAME$ = Jack. The official #}form of the LET statement goes like this: 10 LET X=0 20 LET NUMBER=1024 30 LET TOTAL=NUMBER 40 DIM NAME$$}(25) 50 LET NAME$=George Washington etc The way this ASSIGNMENT statement works, is that it looks for a var%}iable name on the left of the equals sign. It will take what's on THE RIGHT, and put it into the variable on THE LEFT. Got &}that? It loads from the right, into the left. 10 X=256 (sets X equal to 256) 20 25 = SUM (*** WON'T WORK ***)'} 20 SUM = 25 (this is correct) 30 SUM = X (now SUM = 256) It happens that you don't need to put the word LET in (}there for it to work (how handy), and in fact it is nearly poor practice to do so. The 'hip' way to do it is: 10 X=0)} 20 NUMBER=1024 30 TOTAL=NUMBER 40 DIM NAME$(25) 50 NAME$=George Washington We will use LET statements *}in EVERY program we write, but outside this lesson, probably never use the word LET again! Interesting tidbit. We'll see +}more examples as we progress. Note that spaces between variables, the equal sign, and constants, in the LET statement are,} optional. Atari BASIC is loose about this. Spread it out if it looks more readable to you, or eliminate spaces when you're -}running out of room in a 100+ character line. BASIC already has RESERVED WORDS that cannot be chosen for variable names..} For instance, PRINT, STOP, END, SIN, COS, TAN, RND, INT, and others cannot be used for your variable names, as the computer/} already uses those words to call built-in functions. Remember to check for this in programs you just can't seem to de-bug.0}-----------MATH RULES:----------- Once we get numbers into a program with LET statements, we can do math on the numbe1}rs. Here's the Atari BASIC guide to math symbols: + = addition - = subtraction * = multiplication2} / = division ^ = raised to a power For example: 10 REM * MATH DEMO * 20 REM put numbers into varia3}bleS 30 A=2:B=5 40 REM print examples 50 ? A+B 60 ? A-B 70 ? A*B 80 ? A/B 90 ? A^B 100 END Type this progra4}m in and try it. This should print out answers. Note line 30's use of multiple statements on the same line, separated by col5}ons. The question mark (?) is Atari shorthand for PRINT. This saves a lot of typing. These are examples of doing math in 6}the PRINT statement. This is not only allowed, but is usually the preferred way of printing out math results,as opposed to 7}using one statement to do the math, and another to print the result. You have to tell computers to PRINT in order to see a8}nything. You could say: 10 A=1:B=3:C=4 20 ANS=A*B*C 30 END This WILL multiply 1 times 3 times 4, and will 9}put the answer 12 in the variable ANS, but you won't see it, unless you ask to PRINT it. Adding: 25 ? ANS ...would :}print out 12. Math is performed in the order: 1st Anything in parenthesis. 2nd Exponentiation (# to a power) ;} 3rd Division or Multiplication 4th Addition or subtraction Some examples: 3+(4+6)*2 = 23 2^3 = 8 3+4+<}6*2 = 19 3+2^3*2 = 19 (3+4+6)*2 = 26 3+6/2+4*2 = 14 When in doubt, use parenthesis. It never hurts to put th=}em in there. Always count the left and right parens, to make sure you've used an equal number of each.----------------IN>}PUT STATEMENT:---------------- The INPUT statement is a second way to get data into a program (the LET statement is the ?}first). The INPUT statement stops a program, prints a question mark on the screen as a prompt, and waits for you to input fr@}om the keyboard and press RETURN. For example:10 PRINT "Please type in a number and press RETURN"20 INPUT NUMBER30 PA}RINT NUMBER40 END Line 10 is a PROMPT to let the user know what to type in. Line 20 takes in a number and puts it into aB} numeric variable named NUMBER. Line 30 prints it's value on the screen. Try this. Type NEW then enter the program. RUN it aC} few times while trying different numbers for input. Try entering a letter instead of a number. The program crashes. To ID}NPUT letters, you need to specify a string variable name in the INPUT statement. For example:10 DIM NAME$(25)20 PRINT E}"Enter your name and press RETURN"30 INPUT NAME$40 PRINT NAME$50 END You can input ANYTHING into a string variable, butF} only numbers into numeric variables. When you press RETURN without pressing a letter, number or character first, that is cG}alled a null input, and can be tested for by checking for "" (nothing between the quotes.) You can take in multiple pieceH}s of data in the same INPUT statement, by separating variable names with commas.10 DIM NAME$(25)20 PRINT "Type in name, aI}ge, weight"30 INPUT NAME$,AGE,WEIGHT40 PRINT NAME$50 PRINT AGE60 PRINT WEIGHT70 END Separate data items with commas, J}when typing them in. Type all three items, with commas before pressing RETURN. Even though this is POSSIBLE, I believe it iK}s confusing to users, and believe it's much clearer programming to input one piece of data at a time. INPUT statements shL}ould be preceded by PRINT statements cueing the user for what's expected. These PRINT statements are called prompts. Some otM}her BASIC's allow putting a prompt right in the INPUT statement, but...Atari BASIC does not. No real problem. BASIC runnN}ing on microcomputers is a good environment for applications that are interactive with the user, and INPUT provides an easy O}way to accomplish that. INPUT statements are needed when your program performs a process on different data each time, like P}a program that converts Fahrenheit to Centigrade temperatures. While the program is running, it stops to ask for your inputQ}, then continues, using data you've furnished. When I want a user to read a screen of text, then press RETURN to continueR} with the program, I simply dimension a variable B$ early in the program as DIM B$(1), then follow the text with a line likeS}:350 PRINT " ";:INPUT B$:PRINT CHR$(125) This allows the user to read at his/her own pace, then press RT}ETURN which clears the screen and continues the program. B$ is just a "dummy variable", used to bring in a null input. AgaiU}n, CHR$(125) clears the screen. Note the trailing semi-colon after the prompt, to keep the input question mark out on the eV}nd of the prompt line.-------------------------READ AND DATA STATEMENTS:------------------------- A third way to get dW}ata into a program is to put it in a DATA statement, and read it into the program with a READ statement. The format of the RX}EAD statement is READ followed by a variable name, or names separated by commas. The format of the DATA statement is DATAY} followed by numbers, or letters in quotes, with individual pieces of data separated by commas. For example: 10 REAZ}D A,B,C,D 20 PRINT A;" ";B;" ";C;" ";D 30 DATA 1,2,3,4 40 END This program would print 1 2 3 4.Here's mi[}xed input:10 DIM NAME$(20)20 READ NAME$,AGE,WEIGHT30 PRINT NAME$;" ";AGE;" ";WEIGHT40 DATA "John Brown",25,16550 END \} Note that the program has to find string data when there's a string variable in the READ statement, and numeric to go with ]}numeric variable, etc. or it crashes. When the program first encounters a READ statement, is goes to the first DATA stat^}ement (you may have many) and READs the first piece of data in it. BASIC sets a pointer to this data, and increments it one _}piece of data each time a READ statement is executed. Every time another READ is encountered, either in the same or in a `}later READ statements, it reads the next piece of DATA it finds. If there are multiple pieces of data in the first DATA staa}tement, it will read them in order. When it runs out of data in one statement, it continues with the next DATA statement itb} finds. For every READ command you issue, the program must find data, or it crashes. Also note that the command READ A,B,c}C needs to find all three pieces of data, or...it crashes. DATA statements may be placed anywhere in BASIC programs, but d}it is roughly a standard practice to place data at the end. If you follow this practice, a user can examine all the data eae}sily, rather than having to scan the entire listing for scattered data.------------------RESTORE statement:-------------f}----- You may use data over again, by issuing the command RESTORE followed by the line number of a DATA statement. This rg}esets the pointer to the first data item in that line. For example: 10 REM * RESTORE demo * 20 FOR X = 1 to 25q}Ib%DOS SYSb*)DUP SYSb SAUTORUN SYSb _HELP DOCbhBASIC1 DOCb BASIC2 DOCbkBASIC3 DOCbBASIC4 DOC 30 READ NUM 40 PRINT NUM;" "; 50 IF X = 15 THEN RESTORE 100 60 NEXT X 100 DATA 1,2,3,4,5 110 DATr}A 6,7,8,9,10 120 DATA 11,12,13,14,15 200 END This will produce output of:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2s} 3 4 5 6 7 8 9 10 This program READs data into, and PRINTs out a variable named NUM, 25 times. It begins reading data at t}the beginning of line 100, and reads lines 110 and 120 until X = 15. Line 50 then RESTORE's the pointer to the beginning of u}line 100 and it READs the first 10 numbers over again. If desired, we could have RESTOREd to another DATA statement as liv}ne 120. More on FOR-NEXT and IF-THEN in later lessons. The ideal application of READ-DATA statements is the program that w}routinely does calculations with different data each time, as payroll programs, or student grade programs. For programs x}that use a large amount of data, it is easier to enter and verify the accuracy of DATA statements then to type in data one py}iece at a time with INPUT statements. In the OLD DAYS we read data in from punched cards 80 columns wide. The modern day eqz}uivalent of the punch card is the DATA statement that has taken it's place. For example:10 REM * Student Grade Program {}*20 DIM NAME$(20)30 READ NAME$,GR1,GR2,GR3,GR4,GR540 AVEGR=(GR1+GR2+GR3+GR4+GR5)/550 PRINT NAME$;" ";"AVERAGE = ";" ";AVE|}GR60 DATA SALLY SMART,95,91,89,98,9770 END--------------END STATEMENT:-------------- The END statement is required i}}n some programs, and not in others. It is worth putting it at the end of all your programs, period. The END statement stops~} computation, shuts off any sound generators left on, and returns control to BASIC at the READY prompt. For now, put END }on the last line of your program. Later we may tell the program to END if the Quit option is selected from a menu, etc. E}ND is the preferred way for a program to end, as opposed to ending from an error statement.----------------SAMPLE Program}s:---------------- Okay, now let's try some programming exercises that use these principles. We know enough now, to solv}e more complex problems.PROBLEM 2 Write a program that adds, subtracts, multiplies, divides, and raises a number to a p}ower, by putting two numbers in LET statements. Produce output EXACTLY like the following example. Don't use the numbers dir}ectly in the PRINT statements, but use variables. Be sure to allow room for minus signs. Example:The sum of 5 and 1 i}s 6.The difference between 5 and 1 is 4.The product of 5 and 1 is 5.The quotient of 5 divided by 1 is 5.5 raised to} the 1 power is 5.Run this program using the numbers -7 and 39.------------------------------------PROBLEM 2A Writ}e a program that averages a student's grades, and prints out the name, and average. The formula for average is all grades ad}ded together, divided by the number of grades. Format output like: The average of the 7 grades for John Doe is XX.XX.} Find the answer for the following data: (include this as a DATA statement in your program) DATA Jane Jones,79,88,99,90},89,93,83------------------------------------PROBLEM 2B Write a program using INPUT statements that converts temperatu}res from Fahrenheit to Centigrade, as temperatures are input from the keyboard in Fahrenheit. The formula is C = (F-32)5}/9 Format output as:77 degrees F = 25 degrees C.59 degrees F = 15 degrees C. Find the conversions for:a) 14 Fb)} 69.8 Fc) 260.6 Fd) 4262 Fe) -29 F------------------------------------PROBLEM 2C Write a program that converts }hours into minutes using INPUT statements. Format output as: 14.5 hours = 870 minutes Convert the following data:}a) 3.75 hoursb) 99 hoursc) 266 hoursd) 0.3 hourse) 24 hours------------------------------------PROBLEM 2D Write} a program using INPUT statements, that prints a number, it's square, and it's cube, as follows: Number Square C}ube 2 4 8 Run the program for the numbers:a) 14b) -6c) 0.033d) 123e) -0.88-----------}------------------------- This concludes lesson 2 of Learning to Program in Atari BASIC. Be sure to stay tuned for Lesson} 3, which covers: GOTO statement FOR-NEXT statement IF-THEN statement ON-GOTO statement LOOPING } COUNTERS SUMMING We will be able to really get into the nuts and bolts of programming with the addition of loo}ping. Looping is perhaps the single most powerful feature of computers, that distinguishes them from calculators. We will} also learn testing, which allows us to test, and branch to different parts of the program, depending on results. Contac}t me at: Jackson Beebe Prairie Data Fields 807 W. Hill Street Urbana, IL 61801 }byeat: Jackson Beebe Prairie Data Fields 807 W. Hill Street Urbana, IL 61801 TEXT&00LEARNING TO PROGRAM IN ATARI BASIC-------------------------------------LESSON 3: Looping, GOTO, and FOR-NEXT----}---------------------------------(C) COPYRIGHT 1987 by Jackson Beebe This lesson is placed in the Public Domain. Individ}uals, user groups and BBS's may reprint, copy or distribute it, as long as this notice remains intact with the lesson.---}------CONTENTS:--------- LOOPING GOTO Statement ON-GOTO Statement FOR-NEXT Statement This is Lesson} #3 of Learning to program in Atari BASIC, brought to you by Jackson Beebe. Contact me at the address at the end of this les}son.--------LOOPING:-------- Up to this point, our programs have executed "straight down" when RUN. This means execut}ion began at the lowest numbered line, and proceeded sequentially until the last line was executed. Straight down program} logic is very limiting, as each line may only be used once, and no decisions or branching may occur. Most importantly, the }program cannot "loop." Looping, or sending program control back through earlier lines, is one of the most powerful feature}s of a computer. It's what separates computers from calculators. For example, we could write a program that converts Fahr}enheit temperatures to Centigrade, prints the output, then "loops" back to the beginning of the program to convert more dat}a. This would use the code over and over again. Very handy. Try this program: 10 REM * TEMP CONVERSION * 20 ? "INPUT Ce}ntigrade temp "; 30 INPUT CTEMP 40 FTEMP=CTEMP*1.8+32 50 ? CTEMP;"=";FTEMP;" Fahrenheit" 60 ?:? 70 GOTO 20 This} lesson will present an introduction to the concept of looping, and covers the GOTO and the FOR-NEXT statement.-----------}----GOTO Statement:--------------- This is the simplest of all UNCONDITIONAL TRANSFER statements. It's format is: } 80 GOTO 20 A line number, followed by the word GOTO (some BASIC'S allow GO TO) followed by the destination line number}. When encountered in a program, control goes immediately to the specified line number. (You'll receive an error message if} there is no such number.) An example of the GOTO is: 10 PRINT 20 PRINT "TYPE YOUR NAME" 30 DIM NAME$(15)} 40 INPUT NAME$ 50 PRINT:PRINT NAME$ 60 GOTO 10 This program will loop forever, prompting, printing your nam}e, prompting, etc. This is an INFINITE LOOP, as was the temperature conversion program earlier. The GOTO statement is th}e subject of much controversy in BASIC. Many programmers feel it should NEVER be used, as it allows terrible sloppy program}ming, that defies tracing. For example: 10 GOTO 60 20 PRINT "HI" 30 GOTO 50 40 END 50 GOTO 40 }60 GOTO 20 BASIC doesn't "protect you from yourself." It will allow your programs to wander aimlessly, and/or take wild l}eaps, that are nearly impossible to figure out. More structured languages don't permit this. This feature of BASIC is a mix}ed blessing. There are times I find a GOTO pretty handy, e.g. at the end of a menu. When you've tested for every possible} correct input, and haven't found one, then it must be an error, so you erase the invalid entry from the screen and send co}ntrol back to the input to try again, with a GOTO. It's clear enough there. Go easy on these, and don't use them to fix a} sloppy kludge that you've got going, that REALLY needs to be re-written into cleaner code. Please don't give BASIC a bad n}ame !!------------------ON GOTO Statement:------------------ This is like the GOTO, in that it is an UNCONDITIONAL tra}nsfer statement. This has a built-in feature of sending the program to one of several places, depending on the value of som}e variable. It has the syntax: 25 ON (variable) GOTO XX,YY,ZZ If the variable named, has the value 1, control goes to }line XX. If variable = 2, control goes to line YY, and to ZZ if variable = 3, etc. on and on. For example, let's say we h}ave a menu like the one below, and we use a variable named CHOICE to bring in our input. ------------------------ <}1> Load a file <2> Save a file <3> Directory <4> Quit to DOS CHOICE > ? ------------------------} Code would look like this: 5 REM ** MENU DEMO **10 ? CHR$(125)20 ? :? :? " <1> Load a file"30 ? :? " <2> Save} a file"40 ? :? " <3> Directory"50 ? :? " <4> Quit to DOS"60 ? :? :" CHOICE > ";70 INPUT CHOICE80 ON CHOI}CE GOTO 150,200,250,30090 etc100 GOTO 70110 etc120 etc " "900 END This uses an INPUT statement to bring in }a value in CHOICE, either a 1, 2, 3, or 4. Depending on the value, it sends the program to 4 different places, line 150,200},250,or 300. If CHOICE is 1, control will go to line 150. If 2, then line 200. If 3, then line 250, and if 4 then line 30}0. If the value of the variable is 1, then it goes to the first line #, if 2, it goes to the second, and so on. These can s}tring out to more choices that you or I will probably ever need. The destination line numbers don't need to be in any orde}r. For instance, this is okay: 120 ON CHOICE GOTO 15,150,25,95,450 Very handy for menus, and small numbers 1-6 or so. I}f CHOICE is not exactly equal to one of these integers, the program will "fall through" the line. Sometimes you can force l}arge numbers down to low integers by dividing, and taking the INTEGER value, etc.-------------------FOR-NEXT Statement:-}------------------ This is used when you know you want to "crank" a loop a certain NUMBER OF TIMES (like looping 6 times }to guess the LOTTO number (6 digits) or by using a variable to determine how many times to loop. We usually put a FOR and} a NEXT "around" code that we want to execute a set number of times. For example: 50 FOR X = 1 TO 10 60 PRINT "SU}PER" 70 NEXT X 80 END This would "loop" from line 50 to 70, 10 times, printing SUPER each time. The syntax is:}10 FOR (variable) = start# to finish# ...then our routines in here...20 NEXT (variable) FOR-NEXT loops count fr}om the starting number specified, to the ending number. When you reach the ending number, it will not loop back to the FOR }statement again, but will "fall through" the NEXT statement to the next lines of the program. The loop is "finished." For ex}ample: 25 FOR NUMBER = 1 TO 5 . . . . code. . . . . 55 NEXT NUMBER or 25 FOR COUNT }= -3 to 27 . . . . code. . . . . 95 NEXT COUNT There's also an optional ending called STEP, to specify how ma}ny numbers to step each time you count. If you leave it out, it steps 1 at a time by default. It looks like this. 10 }FOR X=1 TO 6 STEP 2 ....... 90 NEXT X This steps 2 at a time. This loop would only run a total of 3 time}s (X=1,X=3,X=5). X starts at 1, then is 3, then 5. (The next value would be 7 , and be greater than 6.) When the value of t}he variable is greater than the ending number, it DOESN'T execute the code in the loop (between FOR and NEXT), but goes to }the next line AFTER the NEXT statement. It "falls thru" the FOR-NEXT loop. FOR-NEXT loops may step from a higher to a low}er or negative number, by specifying a larger starting than ending number, and using a negative STEP value. For example: } 10 FOR NUM = 3 to 1 STEP -1 20 ? NUM 30 NEXT NUM 40 END This would print a list of numbers from 3 to 1. You may} even step by decimal values. We will use FOR-NEXT in MOST programs we write for one purpose or another. EVERY FOR NEED}S A NEXT. They must match up in number (3 of each, etc.) Atari BASIC allows more NEXT than FOR statements like: 125 FOR }NUM = 1 to 50 130 IF NUM = 27 THEN NEXT NUM 135 IF NUM = 28 THEN NEXT NUM 140 IF NUM = 29 THEN NEXT NUM 145 PRINT} NUM 150 NEXT NUM 160 END This program just loops 50 times, and prints the value of the loop variable NUM each time}, except when NUM equals 27, 28, or 29. For those values, the NEXT NUM statements in lines 130-140 send control immediately }back to the FOR statement in line 125, not passing through line 145's PRINT statement. If you have a BASIC compiler, and }try to compile the above program (more on compilers in much later lessons), it probably will blow the compile, seeing too m}any NEXT statements. This could be fixed by changing lines 130-140 from saying NEXT NUM to saying GOTO 150. Just a handy hou}sehold hack! We usually put a FOR-NEXT loop "AROUND" other code, to get the program to do that code, a certain number of }times. The true power of the FOR-NEXT loop comes from the fact that it can use VARIABLES for the starting and finishing num}ber, as well as numbers. This allows it to do something like "check every letter in a word." To do that, we could write a} FOR-NEXT loop from 1 to the length of the word. Lets assume we INPUT a word, using the variable WORD$. Like this: 15 REM} * DEMO * 20 DIM WORD$(20) 25 PRINT "Type in an uppercase word. "; 30 INPUT WORD$ 35 FOR X = 1 TO LEN(WORD$) 40 IF} ASC(WORD$(X,X)) < 65 OR ASC(WORD$(X,X)) > 90 THEN PRINT "**ERROR**":END 45 NEXT X 50 PRINT "THIS WORD IS UPPERCASE" }55 GOTO 25 60 END This program INPUTs a word to the variable WORD$, and checks the ATASCII code to see if it's right fo}r uppercase letters. More on ATASCII later. Look in your manuals. All the letters, numbers, punctuation, etc are assigned n}umbers, i.e. A = 65. Type in the program above, and try it. Type in short words in uppercase, then in mixed upper/lower case}. Now to be technical! (I know it's a pain, but you need this one.) The value of the loop variable (the one specified in }the FOR and the NEXT statement) increments each time it is run on the R-Verter. Booted up on my SX212 and got the 850 statu}s screen. Even though the modem is directly connected, the program thinks it is talking thru an 850. All the commands that }I needed worked just fine on HOMETERM - downloads, disk directories, is that the value of a FOR-NEXT variable is always ONE} greater than the value of the loop, after it finishes. See, it drops though one last time when it's done, and gets increm}ented a final time, even though it's done looping. Programs begin execution at the next line after the NEXT, when the loop} is finished. Again, think of the FOR-NEXT loop as "falling through" when finished. FOR-NEXT is frequently used for a ti}mer, to make the program sit there and wait for a moment. For instance, when printing an intro screen like this: 10 ? CH}R$(125) 20 ?:?:?:? "* * WELCOME TO * *" 30 ?:?:?:? " SNAZZO" 40 ?:?:? " by B. Mudflap" 50 FOR X = 1 TO 40}0:NEXT X 60 ? CHR$(125) 100 main body of program etc. This would clear the screen, print your introduction, wait ther}e aprox. 10 seconds, then clear the screen and begin the program. A larger value in the FOR-NEXT loop will take longer to c}ount up to. Try these timers yourself.--------SUMMARY:--------Up to this point, we know: TWO WAYS TO LOOP: 1) G}OTO statement 2) FOR-NEXT statement Next lesson we'll learn the basic 3rd, the IF-THEN statement, that tests and lo}ops or branches. **************************** BLAST FROM THE PAST: Do you know three ways to get data into a }program? ANSWER: 1) the LET statement 2) the READ-DATA statement 3) the INPUT statement ********}*********************----------------SAMPLE Problems:----------------PROBLEM 3 Write a program that prompts for inpu}t in inches, and shows labeled output in centimeters, using the formula 1 inch = 2.54 centimeters. When it finishes, it s}hould loop back and prompt for input to run again and again. (Quit using BREAK key.)------------------------------------}PROBLEM 3A Write a FOR-NEXT program that produces the printout: 6 5 4 3 2 1 ZERO----------------------------}--------PROBLEM 3B Write a program that prints out all the even numbers between 0 and 50.-----------------------------}-------PROBLEM 3C Write a program that produces a table of numbers, their squares, and their square roots, using the fo}rmat below. The table MUST start at 10, and finish at 1. NUMBER SQUARED SQ. ROOT 10 100 3.3}XXXX 9 81 3 8 64 2.XXXXX . . . . . } . 1 1 1------------------------------------ This concludes lesson 3 of Learning to Program in A}tari BASIC. Be sure to catch Lesson 4 which covers: IF-THEN Statements Counters Summing The concept of l}ooping is very important. You need to begin thinking in terms of "sending the program" to different places when programming,} or directing the flow of the program. REMEMBER: What you can conceive, you can program. It may take a little, or a lot }of work, and may lead you down some new paths, but begin to think in larger terms about programs.-------------------------}----------- Contact me at: Jackson Beebe Prairie Data Fields 807 W. Hill St. Urbana, IL 61801 } bye Jackson Beebe Prairie Data Fields 807 W. Hill St. Urbana, IL 61801 TEXT&00LEARNING TO PROGRAM IN ATARI BASIC-----------------------------------------LESSON 4: Testing, Branching and Count}ers-----------------------------------------(C) COPYRIGHT 1987 by Jackson Beebe This lesson is placed in the Public Dom}ain. Individuals, user groups and BBS's may reprint, copy or distribute it, as long as this notice remains intact with the }lesson.---------CONTENTS:--------- More on LOOPING TESTING BRANCHING IF-THEN Statement RELATION}AL Operators LOGICAL Operators COUNTERS SUMMING This is Lesson #4 of Learning to program in Atari BASIC, br }ought to you by Jackson Beebe. Contact me at the address at the end of the lesson.----------------More on LOOPING:----- }----------- In the last lesson we learned the powerful technique of sending program control back through previous lines o }f code, called LOOPING. As we said in Lesson 3, this is a prime feature that separates computers from calculators. The prog }ram can be sent back through a pile of source code lines, by using a FOR-NEXT or a simple GOTO statement, as: 10 DIM NAM }E$(15) 20 PRINT "Hello. Who are you? "; 30 INPUT NAME$ 40 PRINT:PRINT:PRINT 50 PRINT "Hi there ";NAME$ 60 PRI}NT:PRINT:PRINT 70 GOTO 20--------TESTING:-------- The process that unleashes the power of looping is TESTING. This} gives us the ability to make decisions each time we fall through the code, as "should we continue?"; "should we quit?"; "i}s the input numerical?"; "is X > 42?"; etc. We can write lines of code that accomplish some purpose as guessing the Lotto }number, and loop through multiple times. If we do that, we need to test on each pass for things like, "should we quit?"; }"should output go to screen and/or printer?"; etc. This is accomplished by placing lines in the routine's code, usually at t}he beginning or the end, that test before or after execution. A test at the beginning of a loop is called a Top Test, and} usually tests whether to go through the loop or not. A test at the end is called a Bottom Test, done after the loop is co}mpleted. This usually tests whether to loop back or not. For example: * * TOP TEST * * 10 X = 0 20 IF X} > 10 THEN END 30 X = X + 1 40 PRINT X 50 GOTO 20 or 10 X = 0 20 X = X + 1 30 PRINT X} 40 IF X < 10 THEN 20 50 END * * BOTTOM TEST * * Tests for various conditions and instructions may be gr}ouped together in one location in a program, into "piles" of IF-THEN statements. I prefer this approach, as a pile of line}s makes it easy to find and debug tests. IF-THEN statements execute pretty fast, but you'll notice some slowing when using }a large number.----------BRANCHING:---------- Testing, coupled with looping, gives us the ability to make decisions a}s we loop. An additional ability we have in programming, is BRANCHING. Branching is simply WHERE we send control from one} of our tests. If our test asked "should I quit?", and got a YES response, we would probably send control to the line that }had the END statement, ending the program. Possibilities begin to unfold like petals of a flower, as you "grok" the conc}ept of lines of code with multiple tests for multiple things, sending control to multiple possible places, where multiple th}ings may happen, and on and on and on. Wow! Now THAT'S programming. That's what you've been waiting for, right? Now, how } do we code these tests? These CONDITIONAL TRANSFER OF CONTROL statements? They are the IF-THEN statements.-------------!}-----IF-THEN statement:------------------ This statement takes the basic form of: line# IF (some test) THEN (some s"}tatement)---------------------RELATIONAL Operators:--------------------- We can test for standard mathematical relatio#}nships with the RELATIONAL Operators which are: = equal to < less than > greater than <= $}less than or equal to >= greater than or equal to <> not equal to Some examples: 15 IF X > 89 THEN GRA%}DE$ = "A" 95 IF A <> B THEN C = A + B 135 IF NUM = 99 THEN ? "Bye":END 20 IF X > 14 THEN 1200 10 IF NAME$ = "JACKS&}ON" THEN 135 Characters may be tested for alphabetical order, equal to, greater than etc.------------------LOGICAL Oper'}ators:------------------ Tests may be combined, or substituted using the LOGICAL Operators: AND and OR For(} example:110 IF X >14 AND DAY$ = "M" THEN 1200We can test for a range of numbers as: 15 IF X > 0 AND X < 100 THEN 1)}00 25 IF X < 0 OR X > 100 THEN END Line 15 above, accepts numerical input to the variable X, that is between 0 and *}99.999+. Line 25 rejects input OUTSIDE the range of 0 to 100 (same thing.) Although it looks easy, knowing when to use +}AND and when to use OR in your tests, will be very confusing. As you reason out the logic of multiple tests, you will make ,}the wrong choice many, many times. Be mistrustful of your tests, until they are proven correct by trying good and bad data f-}or input. Always check the use of OR and AND when debugging programs that don't work right. Try numbers on each side of t.}he limits, to make absolutely sure you've got it coded right.These really get confusing when we string tests together as:/} 70 IF (X> 0 AND X< 10 AND FLAG = 1) THEN FLAG = 0 This line tests for three conditions, and if True, sets FLAG = 0. 0}Note parenthesis used between the IF and THEN portion of the statement. These are often required to keep things straight, an1}d always allowable. Note the code following the THEN in this case, is not a GOTO, but simply an instruction. Here's a test 2}to Quit: 80 etc 90 DIM KEYIN$ (1) 100 ? "QUIT (Y/N) ? "; 110 INPUT KEYIN$ 120 IF KEYIN$="Y" or KEYIN$="y" TH3}EN ? CHR$(125):END 130 etc This code dimensions a one character string variable KEYIN$ for input. It tests for both an 4}upper and lower case y, clears the screen and ends the program if found. Testing for both upper and lower case is the best i5}dea, as the program will work, regardless of how the user has the upper/lower case toggled. This is an example of error 6}checking the input, a process that bullet-proofs a program against incorrect input causing a crash. This is often a factor7} that separates smooth professional programs from rough hacks. We will expand on this process as we learn. Note the quot8}es around alphabetic characters being tested for, and that Atari BASIC is forgiving about whether you use spaces before and 9}after the relational operators, and variables, etc. Also note we MUST restate the variable when using AND and OR. Here's W:}RONG code that WON'T work: (wrong) 10 IF A<6 AND >10 THEN END (right) 10 IF A<6 AND A>10 THEN END The syntax checker;} in the built-in BASIC editor will catch this error. Multiple statements may be hung on the end of an IF-THEN, separated b<}y colons. The code following the THEN will be executed when the IF-THEN statement tests TRUE. All code past the THEN will=} be executed up to the permissible maximum line length of three screen lines. The code following the THEN is never executed>} if the statement tests False. For example: 10 FOR X = 1 TO 25 20 IF X>=6 AND X<=10 THEN ? X 30 NEXT X 40 END This p?}rogram prints: 6 7 8 9 10 The equal sign tests for EXACTLY equal to, and 5.9999 is NOT equal to 6. T@}his can be tricky. It is common practice to use < and > to test for numbers, or <= and >= when possible, to avoid numeric eA}rrors resulting from multiplication or division causing slight inequality. Strings may be tested, and < and > will test forB} alphabetical order of the first letters of strings. Again, don't trust your eyes and brain to know whether you've arrangeC}d your AND's and OR's, parentheses and logic correctly. It always LOOKS right. Use correct and incorrect input, and make sD}ure by trial and error that everything is correct. Some BASIC's support an ELSE addition to the IF-THEN statement, but AtE}ari BASIC does not. Don't worry, we don't really need it. You can always arrange code to achieve the effect you want. WheF}n an IF-THEN statement is False, execution resumes at the very next line, and the IF-THEN is NOT executed. The opportunitG}ies, and combinations are endless, and knowing a few good "hacks" is what separates new from experienced programmers. We wiH}ll continue to learn about IF-THEN statements for a long time.---------COUNTERS:--------- Often, we wish to keep tracI}k of how many times we have gone through a loop. We may want to do something every other trip through, or count when to end,J} or keep track of how many times we've done a thing. This is done with COUNTERS, which are +1 or adding statements placedK} within the body of the loop. These let the computer do the counting, freeing us from this chore, which is the whole idea bL}ehind using and programming computers. These often look like: 10 X = X + 1 70 TOTAL = TOTAL - 5 25 COUNT = M}COUNT + 1 Note the way these are coded. Counters say, "a variable equals itself plus something". The variable name appearN}s on each side of the equal sign, with the "plus something" on the right. Remember a LET statement takes what's on the righO}t of the equal sign, and assigns it to what's on the left of the equal sign. It's a little hard to think so elementary atP} first, X = X + 1, but becomes second nature soon. I'm serious, they're hard to catch on to coding.--------SUMMERS:-----Q}--- SUMMER is not a proper programming term, but that's what I call these. Summer's are utilities much like counters, butR} rather than counting, they total or add together or accumulate a running sum total number. For example, a summer in a payrS}oll program keeps track of how much we have earned to date in the year. These are coded much like counters, but often haT}ve a variable for a "plus something" on the right hand side. Some examples: 15 TOTHOURS = TOTHOURS + HOURS 10 YTDSAL =U} YTDSAL + WEEKSAL 55 SUM = SUM + (14.7*TAX-INTEREST) 10 TOTAL = TOTAL + ADDON If counters usually tell us "how many"V} a thing is now, then summers keep track of "how much" we have now. Trust me! This will make sense someday. Sometimes whenW} a program you are writing is acting up, and you can't figure it out, you can install some counters and/or summers in the coX}de, and RUN it. Break in with the BREAK key, and ask it to print the value of a counter or summer in immediate mode at thY}e READY prompt, like "? SUMM" or "? TOTAL" or "? COUNT". It may be helpful to see if it's looped more or less times than yoZ}u had thought, or perhaps you find it got stuck after a set number of loops. When the program's debugged, take out the lines[}. ----------------------------------- Putting It All Together------------------------------------ Let's write a p\}rogram that puts this all together, that you can continue to work on and develop, and learn on. Let's imagine you are a tea]}cher, who needs to average student grades for the entire semester, and assign a letter grade. If doing this by hand, we ^}would add all of a student's grades, divide by the number of grades, and find a numerical average. This would then be compa_}red to a range of numerical grades and letter grades. We must count the number of grades each student has, to find the corre`}ct number to divide by. This if often confusing when students have a different number of grades in a class, and could lead a}to an error. Let's write a program that calculates these grades on our Atari computer in BASIC. When calculating the averb}age, it must keep track of how many grades we enter for each student, automatically choosing the correct divisor. The proc}gram should prompt you for correct input, and error check it for correctness. It should stop taking grades and display the ad}verage when we type in a grade of 999 to signal the end of input. We may add to this program at some point, so we'll stare}t numbering it at 1000. Leaves lots of room "below." 1000 REM ** EZ-GRADE ** 1010 REM JACKSON B 6/87 1020 REM 1f}030 REM CLEAR,INITIALIZE,PROMPT,IN 1040 ? CHR$(125):TOTAL = 0:COUNT = 0 1050 ? :? :? "Enter grade "; 1060 INPUT GRADE 10g}70 REM 1080 REM TEST,INCREMENT,SUM,LOOP 1090 IF GRADE = 999 THEN 1160 1100 IF GRADE <0 OR GRADE > 100 THEN GOTO 1050 111h}0 TOTAL = TOTAL + GRADE 1120 COUNT = COUNT + 1 1130 GOTO 1050 1140 REM 1150 REM AVERAGE AND OUTPUT 1160 AVG = TOTAL / Ci}OUNT 1170 ? :? "The AVERAGE for these "; COUNT;" grades is ";AVG 1180 ? :? "(Press 9 to enter more grades) "; 1190 INPUT j}M 1200 IF M = 9 THEN 1040 1210 END This program uses a counter (COUNT) to keep track of the number of grades entered, ak}nd a summer (TOTAL) to keep a running total. Entering a 9 after an average, will continue the program. Any other key will l}end the program. Note that the counter and summer are initialized (set to zero) OUTSIDE the main loop.----------------m}Sample Problems:----------------PROBLEM 4 Add lines to EZ-GRADE to determine a letter grade A, B, C, etc, in additionan}l to a numerical average. (HINT - add a pile of IF-THEN's after line 1170 that test whether input is between 70 and 79, 80 o}and 89 etc, and assign a letter to a variable. Use a one character string variable to hold the letter grade, that is dimensp}ioned outside the loop (line 1135.)------------------------------------PROBLEM 4A Modify EZ-GRADE so that instead of tq}yping in 999 to signal the end of data, you simply press RETURN without having entered a grade (a NULL entry.) Have it pror}mpt whether you really want to stop entering data before it calculates the average and letter grade. (HINT - you need a ss}tring variable to bring in a plain carriage return. The VAL function will translate your string input into a number.) Tht}e way you test for an empty carriage return (RETURN) is to test the input for equality with two sets of quotation marks bacu}k-to-back with nothing between them as: 195 IF NAME$ = "" THEN 255 This tests True for a null input, and goes to liv}ne 255. You MUST hit the RETURN key to pass an INPUT statement in BASIC. ------------------------------------PROBLEM 4Bw} Write a GUESS THE SECRET NUMBER program. Use the following line early in the program, which will generate a random numberx} between 1 and 100, and assign it to the variable SNUM. Write your program to prompt the player for a number from 1 to 10y}0, and give feedback if the guess is higher, lower, or equal to the secret number (a winner.) Write it to loop 10 times, thz}en signal that the 10 guesses are up, and you lose! 35 SNUM = INT(RND(0)*100+1)------------------------------------{}PROBLEM 4C Write a program that asks you to guess the capitol of 5 states, and gives you a grade from 0 to 100 on your an|}swers. ------------------------------------ This concludes Lesson 4 of Learning to Program in Atari BASIC. Be sure to c}}atch Lesson 5 which includes: FUNCTIONS INT(), RND(), VAL(), SQR(), ASC(), CHR$(), ABS(), SIN() PLUS:~} More tricks and treats Let's back up for one moment, and recall a rap we had in Lesson 1, in which I identified 3 tasks }beginners face in learning to program. 1. Learning to operate the hardware. 2. Learning to program. 3. Learning the BAS}IC language. Once you learn most of the basic programming concepts and structures, you will never need to learn them over} again, if you pursue other languages. For instance, you will not relearn the concepts of testing, branching and counters. }You will simply ask "What's the syntax to...test, loop, branch, etc." It is natural to be very confused right now. Do not} quit because you are confused. That simply means your brain is making the correct thinking adjustments. It is natural to d}ream about programs and problems when working on new projects. Relax, it's not permanent, and some of your best ideas just }pop into your head after days of muddled thoughts. ------------------------------------Contact me at: Jackson Beebe } Prairie Data Fields 807 W. Hill Street Urbana, IL 61801 byet me at: Jackson Beebe `