home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / basic / basictut.ark / TUTR.07 < prev    next >
Encoding:
Text File  |  1985-02-10  |  8.1 KB  |  157 lines

  1. 3000    ' tutor 7
  2. 3010    GOSUB 37100
  3. 3020    T5$ = SPACE$(5) : T10$ = SPACE$(10) : T15$ = SPACE$(15) :VT$ = CHR$(11)
  4. 3030    GOTO 3070
  5. 3040    PRINT ELR$;T10$;"No such choice! Let's try again.";VT$;VT$;CR$;
  6. 3050    RETURN
  7.  
  8.  
  9. 3060    GOSUB 37100
  10. 3070    PRINT T10$;"   For a loop, we need special machine instructions. What form"
  11. 3080    PRINT T10$;"these take depends on how the computer is told the number of"
  12. 3090    PRINT T10$;"necessary iterations. It may be asked to decide this, which"
  13. 3100    PRINT T10$;"means that 'decision-making' can enter into the loop process."
  14. 3110    PRINT
  15. 3120    PRINT T10$;"   In the program for computing radius vectors, the computer"
  16. 3130    PRINT T10$;"made a decision as to how many radius vectors to compute, based"
  17. 3140    PRINT T10$;"on the amount of data provided. There are many reasons why such"
  18. 3150    PRINT T10$;"a means of decision-making is impractical for ordinary purposes."
  19. 3160    PRINT T10$;"For one thing, you may not want to use all of the data for a"
  20. 3170    PRINT T10$;"particular 'run'. Other reasons will suggest themselves."
  21. 3180    PRINT
  22. 3190    PRINT T10$;"   Ordinary decision-making is done by means of one of these"
  23. 3200    PRINT T10$;"four code words: (1) 'NEXT' (2) 'THEN' (3) 'IF' or (4) 'FOR'"
  24. 3210    PRINT T10$;"Which do you think it might be (use the number of the choice,"
  25. 3220    PRINT T10$;"following my question mark)..? ";
  26. 3230    GOSUB 40900 : Q$ = CVTSTR$
  27. 3240    PRINT
  28. 3250    IF Q$ <= "4" AND Q$ > "0" THEN 3280
  29. 3260    GOSUB 3040
  30. 3270    GOTO 3220
  31. 3280    IF Q$ = "3" THEN 3310
  32. 3290    PRINT ELR$;T10$;"This is used for something else. Try again.";VT$;VT$;CR$; 
  33. 3300    GOTO 3220
  34. 3310    GOSUB 37100
  35. 3320    PRINT T15$;"    (1) 'NEXT' (2) 'THEN' (3) 'IF' or (4) 'FOR'";CRLF$
  36. 3330    PRINT T10$;"   You're right. 'IF' warns the computer that it is to make"
  37. 3340    PRINT T10$;"a choice, based on a given condition. Of course since a computer"
  38. 3350    PRINT T10$;"can't actually think (almost but not quite), it needs another"
  39. 3360    PRINT T10$;"code word to tell it what to do based on the choice. That other"
  40. 3370    PRINT T10$;"word is also one of those four listed above. Which do you"
  41. 3380    PRINT T10$;"suggest it might be? ";
  42. 3390    GOSUB 40900 : J$ = CVTSTR$
  43. 3400    PRINT
  44. 3410    IF J$ = "2" THEN 3440
  45. 3420    PRINT T10$;"You should have typed '2', because 'THEN' is the word that"
  46. 3430    GOTO 3450
  47. 3440    PRINT T10$;"   Very Good! And to explain: the word 'THEN' is the one that"
  48. 3450    PRINT T10$;"conditionally (i.e., depending on some condition) 'clues' the"
  49. 3460    PRINT T10$;"machine as to just what statement (identified by line number)"
  50. 3470    PRINT T10$;"is to be used next in the program. 'IF' and 'THEN' are combined"
  51. 3480    PRINT T10$;"in a particular way. One of the following is the correct form:"
  52. 3490    PRINT
  53. 3500    PRINT T10$;"     (1) IF X = 4 THEN 355     (3) IF X EQUALS 4 THEN 355"
  54. 3510    PRINT T10$;"     (2) IF X THEN 355         (4) IF X IS 4 THEN 355"
  55. 3520    PRINT
  56. 3530    PRINT T10$;"Pick the one (number of choice) which seems correct: ";
  57. 3540    GOSUB 40900 : L$ = CVTSTR$
  58. 3550    PRINT
  59. 3560    IF L$ = "1" THEN 3660
  60. 3570    IF L$ = "2" THEN 3660
  61. 3580    IF L$ = "3" THEN 3620
  62. 3590    IF L$ = "4" THEN 3620
  63. 3600    GOSUB 3040
  64. 3610    GOTO 3530
  65. 3620    PRINT ELR$;T10$;"No, but you have the right idea. Try again.";
  66.  
  67.         VT$;VT$;CR$;
  68. 3630    GOTO 3530
  69. 3640    PRINT T10$;"This doesn't actually put any condition on 'X'. Guess again!";
  70.  
  71.         VT$;VT$;CR$;
  72. 3650    GOTO 3530
  73. 3660    GOSUB 37100
  74. 3670    PRINT T10$;"   You figured that one out. Either '1' or '2' can be used, but"
  75. 3672    print t10$;"for different purposes. The '=' symbol in number '1' (rather "
  76. 3680    PRINT T10$;"than the word 'EQUALS' in 'X = 4') creates a condition of 'true' "
  77. 3682    print t10$;"if X = 4, or 'false' if X <> 4. In '2', a condition of 'true' "
  78. 3684    print t10$;"is created if there is ANYTHING in X and a condition of 'false' "
  79. 3690    PRINT T10$;"is created if X is 0. The '355' is a legitimate line number, "
  80. 3700    PRINT T10$;"since any number through 65529 is acceptable. In the case of 1, "
  81. 3710    PRINT T10$;"the computer will transfer control to line 355 only if 'X' is "
  82. 3720    PRINT T10$;"exactly 4; otherwise, it will ignore the instruction and continue "
  83. 3722    print t10$;"with the next one."
  84. 3730    PRINT : PRINT T10$;"   Actually, after the word 'THEN' you can either put a "
  85. 3740    PRINT T10$;"line number or any valid basic statement. For example:";CRLF$
  86. 3750    PRINT TAB(20);"IF A < 0 THEN LET A = A + 1";CRLF$
  87. 3760    PRINT T10$;"   In this case, if A is negative, the new value of A is one"
  88. 3770    PRINT T10$;"greater than the old value of A."
  89. 3780    GOSUB 37000 : GOSUB 37100
  90. 3790    PRINT T10$;"Let's play a matching game with the following:";CRLF$
  91. 3800    GOSUB 5000
  92. 3810    PRINT T10$;"The three symbols '=', '<', and '>', shown alone and in various"
  93. 3820    PRINT T10$;"combinations in the choices (1) through (9), give conditional"
  94. 3830    PRINT T10$;"control to the 'IF' statement. Six of the choices have meanings"
  95. 3840    PRINT T10$;"given by the letter-identified list (a) through (f). Now"
  96. 3850    PRINT T10$;"see if you can match the symbols with the meanings."
  97. 3860    PRINT CRLF$;FNCENTER$("press any key for the drill"); :
  98.  
  99.         FOR CT = 1 TO 27 :PRINT CHR$(8); : NEXT CT : GOSUB 40800
  100. 3870    GOSUB 37100 : GOSUB 5000
  101. 3880    PRINT T10$;"  Decide what sequence of number choices agree with the letter"
  102. 3890    PRINT T10$;"sequence, and type those six numbers separated by commas (for"
  103. 3900    PRINT T10$;"instance, if you were to select the first 6 in order, you would"
  104. 3910    PRINT T10$;"type them as: 1,2,3,4,5,6)."
  105. 3920    PRINT CRLF$;ELR$;T10$;"What's your answer? ";
  106. 3930    LINE INPUT A$ :CVTSTR$ = A$ :GOSUB 40400 : A$ = CVTSTR$ 'INPUT "",A$, B$, C$, D$, E$, F$
  107. 3940    PRINT EES$;
  108. 3950    TST = INSTR(A$,"@") : IF TST > 0 THEN SYSTEM
  109. 3960    IF NOT A$ = "5,6,8,1,4,7" THEN 3990
  110. 3970    PRINT CRLF$;T10$;"Nice going - you got it completely right. So now remember that"
  111. 3980    print t10$; : GOTO 4070
  112. 3990    PRINT EES$;CRLF$;T10$;"   Won't work. If you want me to tell you, type 'yes' - if you"
  113. 4000    PRINT T10$;"want to try again, type anything else.";
  114. 4010    GOSUB 40900 : G$ = CVTSTR$
  115. 4020    PRINT
  116. 4030    IF LEFT$(G$,1) = "Y" THEN 4060
  117. 4040    PRINT VT$;VT$;VT$;VT$;VT$;VT$;VT$;CR$;
  118. 4050    GOTO 3910
  119. 4060    PRINT VT$;VT$;VT$;ELR$;T10$;"   Well, you should have had 5,6,8,1,4,7 in that order. "
  120. 4062    print t10$;"You see, ";
  121. 4070    PRINT "'=' means 'is equal to', '<>' means 'is not equal to', '<'"
  122. 4080    PRINT T10$;"means 'is less than', '>' means 'is greater than', '<=' means"
  123. 4090    PRINT T10$;"'is less than or equal to', and '>=' means 'is greater than or"
  124. 4100    PRINT T10$;"equal to'. The symbols not used above are invalid."
  125. 4110    GOSUB 37000 : GOSUB 37100 : PRINT FNPOSCUR$(8,1);
  126. 4120    PRINT T10$;"   Now that you understand 'IF' and 'THEN', let's see how we can"
  127. 4130    PRINT T10$;"use them to control iterations. This will be an 'If' loop, and"
  128. 4140    PRINT T10$;"the computer will decide the number of times we go through it."
  129. 4150    PRINT T10$;"We'll take a look at an example of this and work out a usable"
  130. 4160    PRINT T10$;"solution, but first we'll need to call in (TUTR.08) from the menu.";CRLF$
  131. 4180    PRINT FNCENTER$("press any key for menu"); :
  132. 4190    FOR CT = 1 TO 22 : PRINT CHR$(8); : NEXT CT : GOSUB 40800
  133. 4200    GOTO 39999
  134.  
  135.  
  136. 5000    PRINT T15$;"(a) 'is equal to'                    (1) >    (6) <>"
  137. 5010    PRINT T15$;"(b) 'is not equal to'                (2) =>   (7) >="
  138. 5020    PRINT T15$;"(c) 'is less than'                   (3) ><   (8) <"
  139. 5030    PRINT T15$;"(d) 'is greater than'                (4) <=   (9) =<"
  140. 5040    PRINT T15$;"(e) 'is less than or equal to'       (5) ="
  141. 5050    PRINT T15$;"(f) 'is greater than or equal to'";CRLF$
  142. 5099    RETURN
  143.  
  144.  
  145. 5100    GOSUB 40200 : GOSUB 40300 : RETURN
  146. 37000    'press any key pause
  147. 37010    PRINT T10$;CRLF$;CRLF$;FNCENTER$("press any key to continue");
  148. 37020    FOR CT= 1 TO 25 : PRINT CHR$(8); : NEXT CT
  149. 37030    GOSUB 40800
  150. 37099    RETURN
  151.  
  152.  
  153. 37100    ' heading
  154. 37110    PRINT CLS$;FNPOSCUR$(4,1);FNCENTER$("Tutor -- Lesson 7");CRLF$
  155. 37199    RETURN
  156.  
  157.  
  158. 38000    ' converted for Non-linear Systems, Kaypro Educational Division
  159. 38010    ' by t.crew , Simple Software, San Diego CA
  160. 38020    ' has to be run with mentutr to get all variables
  161. 38030    ' tutor lesson 7 version 2.0  released to nls 1 aug 83
  162.  
  163.  
  164. 39999    RUN "MENU" 'end of overlay
  165.  
  166.  
  167.