SECTION D - PRIMER FILE PRIMER.D LOOPS ***** A LOOP is when an instruction or a set of instructions keeps repeating itself. It has a variety of uses and is a very important part of the programmers armoury. Unfortunately, however, a loop can be formed accidentally and can be alarming to the beginner. At one extreme, the screen may fill rapidly with repeated characters, at the other the screen may go static or blank. Dealing with ACCIDENTAL LOOPS === Most times all that is required when working with pure BASIC is to press the STOP key, then investigate the cause. A prime cause is careless use of the GOTO command.For example the single line program { 10 PRINT "Hello";: GOTO 10 } will cause the word Hello to be printed until it fills the screen. The only way to stop it is to press the STOP key( or switch off) This is bad enough but if the line was { 10 GOTO 10} the screen would become blank. Try it if you like! In practice ,the cause may not be so obvious, and may need a little detective work. When working closer to the fundamental controls of the computer such as when using machine code with BASIC, accidental loops are in general more pernicious and may not respond to the "STOP" treatment. In this case it may be necessary to reboot CP/M using SHIFT/EXTRA/EXIT or even switch off and then on again before restarting CP/M. In both cases all work that has not been saved to disc will be lost. The golden rule is therefore always to SAVE a program to disc before attempting to run it. This message is included here for information in case you copy a BASIC program containing machine code from a magazine. It should never happen with this course,except perhaps when dealing with ESCAPE CODES Getting back to intentional loops; they can be conditional or unconditional. A conditional loop is one in which the looping will end when a predetermined condition is met. For example we could arrange for the loop to repeat itself a set number of times or to stop when a codeword is typed into the keyboard. An unconditional loop is one which continues to repeat itself until stopped by the operator. One example of this is an advertising program which runs through then has a GOTO to the start again. You have probably seen these in shop windows. In PRIMER we shall only deal with the most common loop, the FOR....NEXT loop. This takes takes the form { FOR a=1 to 500: NEXT } Nothing will appear on the screen, but this loop is used as a time delay , as the machine will count from 1 to 500 before carrying on with the program. Two more examples of this can be seen in the listing in Part 1- Introductory text.. A useful variation on the above is {FOR a=1 TO 500 STEP 2:NEXT } when the count will go 1,3,5 etc.,in steps of 2. Counts can also be decreased as { FOR a =500 TO 1: NEXT } . Practical uses for the FOR...NEXT loop are given in the next listing coming up. Please take the opportunity to experiment with the examples given and also to find and recognise FOR...NEXT loops in other BASIC programs. END of file PRIMER.D  and also to find and recognise FOR...NEXT loops in other