home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Discy Business / Discy Business.hdv / DEV.CD / GUIDED.TOURS / IIC.PLUS.TOUR / BASIC / PROGRAM.TEXT < prev    next >
Encoding:
Text File  |  1988-04-09  |  4.2 KB  |  314 lines  |  [04] ASCII Text (0x0000)

  1. %
  2. 3
  3. 10
  4. 1
  5. 38
  6.        WRITING PROGRAMS
  7.  
  8. With Applesoft BASIC, you can do
  9. things now or you can do them
  10. later.
  11. ^
  12. &
  13.  
  14.  
  15. When you type a statement like...
  16. ^
  17. %
  18. 3
  19. 12
  20. 1
  21. 38
  22. ...the computer carries out your
  23. instructions right now.  That is,
  24. your instructions are carried out
  25. by the computer immediately after
  26. you press RETURN.  This is called
  27. (logically enough) IMMEDIATE
  28. EXECUTION.
  29. ^
  30. &
  31. Immediate execution is fine if
  32. you want immediate results.
  33. But what if you want to put
  34. several statements together and
  35. store them until later?
  36. ^
  37. %
  38. 3
  39. 9
  40. 1
  41. 38
  42. You must use DEFERRED EXECUTION
  43. if you want to make your Apple II
  44. save statements for later use.
  45. ^
  46. &
  47. Deferred execution means that you
  48. tell the computer to store your
  49. instructions until you give the
  50. go-ahead to execute them.
  51. ^
  52. &
  53. To write an instruction in
  54. deferred execution, simply type
  55. a number in front of the
  56. statement.  For instance...
  57. ^
  58. &
  59. When you press RETURN, nothing
  60. happens on the screen.
  61. But the statement is stored in
  62. the computer's memory.
  63. ^
  64. &
  65.  
  66. To execute the PRINT statement,
  67. type...
  68. ^
  69. &
  70. The RUN command causes the
  71. Apple II to execute all of the
  72. statements stored in memory.
  73. ^
  74. &
  75. Any time you put numbers in front
  76. of one or more statements, the
  77. resulting lines are stored in
  78. memory as a PROGRAM.
  79. ^
  80. &
  81. The number of the statement (in
  82. this case 10) is called the LINE
  83. NUMBER.
  84. ^
  85. &
  86. You can add another line by typing
  87. another line number and a
  88. statement.  For instance...
  89. ^
  90. &
  91. Please execute the new program
  92. (the command to execute a program
  93. is RUN).
  94. ^
  95. %
  96. 3
  97. 8
  98. 1
  99. 38
  100. Very good!  You just ran an
  101. Applesoft BASIC program.
  102. ^
  103. &
  104. Notice that line number 10 was
  105. executed first, and line 30 was
  106. executed second.
  107. ^
  108. &
  109. BASIC executes statements in the
  110. order of the line numbers, begin-
  111. ning with the smallest number.
  112. ^
  113. &
  114. Now let's say you want to insert a
  115. line between line 10 and line 30.
  116. No problem!  Just type...
  117. ^
  118. %
  119. 3
  120. 10
  121. 1
  122. 38
  123. The line numbers indicate the
  124. order in which the lines are
  125. executed, so line 20 will
  126. print between line 10 and
  127. line 30.
  128. ^
  129. %
  130. 3
  131. 8
  132. 1
  133. 38
  134. Type RUN and notice that the
  135. lines print in the order of
  136. the line numbers.
  137. ^
  138. %
  139. 3
  140. 9
  141. 1
  142. 38
  143. Wonderful!  You can see that
  144. the lines were indeed printed
  145. in the correct order.
  146. ^
  147. &
  148. Now it's up to you to finish
  149. this verse with one more PRINT
  150. statement.  Please type your
  151. statement on line 40.
  152. ^
  153. %
  154. 3
  155. 7
  156. 1
  157. 38
  158. Hey, you're really getting the
  159. hang of it,
  160. ^
  161. %
  162. 3
  163. 11
  164. 1
  165. 38
  166. Every program should end with
  167. an END statement.  The END
  168. statement tells the computer that
  169. the program is finished and
  170. that it doesn't have any more
  171. work to do.
  172. ^
  173. %
  174. 3
  175. 7
  176. 1
  177. 38
  178. To add the END statement, you type
  179. a line number and the word END.
  180. ^
  181. &
  182. Your program is now complete.
  183. Why don't you run it?
  184. ^
  185. %
  186. 3
  187. 10
  188. 1
  189. 38
  190. The computer stops when it reaches
  191. line 50, the END statement.
  192. Notice that END isn't printed
  193. when the program is run because it
  194. isn't part of a PRINT statement.
  195. ^
  196. %
  197. 3
  198. 10
  199. 1
  200. 38
  201. But what if you want to look
  202. at all the program statements
  203. after you've typed them into
  204. memory?  It's easy.  You just
  205. type...
  206. ^
  207. %
  208. 3
  209. 8
  210. 1
  211. 38
  212. The LIST command shows all of
  213. the program lines in memory in
  214. the correct order.
  215. ^
  216. &
  217. Changing and deleting program
  218. lines is a snap.
  219. ^
  220. &
  221. Let's say you've decided that
  222. your rhyme could be improved
  223. by changing line 40.
  224. ^
  225. &
  226. To change the line, just type
  227. the line number and type a new
  228. PRINT statement.
  229. ^
  230. &
  231. Why not try it now. Change
  232. line 40 by typing 40 and a new
  233. PRINT statement.
  234. ^
  235. %
  236. 3
  237. 8
  238. 1
  239. 38
  240. You did it!
  241. Now type LIST to make sure
  242. that your program did change.
  243. ^
  244. %
  245. 3
  246. 8
  247. 1
  248. 38
  249. Notice that the new line 40
  250. is substituted for the old
  251. line 40.
  252. ^
  253. %
  254. 3
  255. 6
  256. 1
  257. 38
  258. Now run the new program.
  259. ^
  260. %
  261. 3
  262. 10
  263. 1
  264. 38
  265. You're doing VERY well!
  266. Deleting lines is just as easy.
  267. To delete a line, simply type
  268. the line number of the line you
  269. want to delete and press RETURN.
  270. ^
  271. &
  272. For instance, if you decide that
  273. you don't want line 30 in your
  274. program, you can erase it by
  275. typing 30 and pressing RETURN.
  276. Try erasing line 30 now.
  277. ^
  278. %
  279. 3
  280. 7
  281. 1
  282. 38
  283. Excellent!  Now list the
  284. program.
  285. ^
  286. %
  287. 3
  288. 7
  289. 1
  290. 38
  291. You can see that you have
  292. deleted line 30.
  293. ^
  294. %
  295. 3
  296. 9
  297. 1
  298. 38
  299. You may be upset that you just
  300. lost a line of your poem. Press
  301. RETURN and we'll do you a favor
  302. and retype line 30 for you.
  303. ^
  304. &
  305. There you go.  Your program is
  306. back to its original elegance.
  307. ^
  308. &
  309. The next step is to save your
  310. program.  Press RETURN to go to
  311. the next section, or press ESC
  312. to go back to the menu.
  313. ^
  314.