The program below uses a much more complex function, containing statements

which are explained in the next few sections:

10 MODE 135

20 PR0Cinput_word

30 END

40 DEFPROCinput_word

50 INPUT"Type in a word " ,word$

60 PRINT'"An anagram of that word is ";FNanagram(word$)

70 ENDPROC

80 DEFFNanagram(choice$)

90 length%=LEN(choice$)

100 FOR count=1 TO length%

110 random_letter%=RND( Length%-1 )

120 choice$=RIGHT$(choice$,length%-random_

letter%)+MID$(choice$,random_letter%,1 )+LEFT$(choice$,random_

letter%-1 )

130 NEXT

140 =choice$

Loops

FOR...NEXT

The real power of computers comes from their ability to repeat instructions.

This can transform trivial programs so that they produce very impressive

results.

The FOR...NEXT loop makes the computer repeat a set of instructions a fixed

number of times:

10 MODE 128

20 FOR count=1 TO 100

30 PRINT count

40 NEXT count

Line 20 is the start of the loop, with the variable count being set to 1 initially.

After printing the value of count at line 30, the computer finds the NEXT

statement which indicates the end of the loop.

At this point count is increased by I. Provided that count has not gone beyond

the end value of 100 the computer now repeats all the instructions again.

Line 40 can be written as just:

40 NEXT

C 37