237 140 REM and use it to pick a random word 150 B$=MID$(A$,5*R-4,5) 160 REM print a message 170 PRINT "My ";B$;" hurts" 180 REM get another random word 190 R=RND(7) 200 B$=MID$(A$,5*R-4,5) 210 REM and print out a second message 220 PRINT "Is your ";B$;" all right?" 230 NEXT count Now look at the same program using a subroutine and with the REM s (remarks) removed. 110 A$="hand mouthear leg arm chestelbow" 120 FOR count=1 TO 10 150 GOSUB 810 170 PRINT "MY ";B$;" hurts" 190 GOSUB 810 220 PRINT "Is your ";B$;" all right?" 230 NEXT count 240 END 810 B$=MID$(A$,5*RND(7)-4,5) 820 RETURN The 7 in line 810 is there to select one of the seven words in A$.
In line 810 both the 5s are there because each word contains five letters or spaces. It is essential that all the words contain the same number of characters. Finally, here is the same program written with a string function, with REM s left out and generally cleaned up. 110 A$="hand mouthear leg arm chestelbow" 120 FOR count=1 TO 10 170 PRINT "My ";FNword;" hurts" 220 PRINT "Is your ";FNword;" all right?" 230 NEXT count 240 END 800 DEF FNword= MID$(A$,5*RND(7)-4,5)