10 PRINT "PROGRAM FILE 46: INTERACTION OF CONTROL STATEMENTS WITH"
20 PRINT "        THE FOR-STATEMENT."
30 PRINT "    ANSI STANDARD 11.2, 11.4, 10.2, 10.4"
40 PRINT
50 PRINT "SECTION 46.1: INTERACTION OF GOSUB-STATEMENT WITH"
60 PRINT "        THE FOR-STATEMENT."
70 PRINT
80 PRINT "THIS SECTION TESTS THAT A GOSUB ROUTINE CAN BE EXPECTED"
90 PRINT "FROM WITHIN A FOR-BLOCK."
100 PRINT
110 PRINT "               BEGIN TEST."
120 LET A1=8
130 LET B1=-5
140 LET C1=-3
150 LET T2=4
160 PRINT
170 PRINT "CONTROL VARIABLE:"
180 PRINT "SHOULD BE","ACTUAL","RESULT"
190 LET A2=A1
200 LET B2=B1
210 LET C2=C1
220 LET I2=A2
230 REM S1 IS ERROR SWITCH
240 LET S1=0
250 REM T1 IS LOOP COUNT
260 LET T1=0
270 FOR I1=A1 TO B1 STEP C1
280    LET T1=T1+1
290    LET M$="  OK  "
300    IF I1=I2 THEN 330
310    LET M$="FAILED"
320    LET S1=1
330    PRINT I2,I1,M$
340    LET T9=99
350    GOSUB 650
360    IF T9=9 THEN 390
370    PRINT "GOSUB FAILED TO TAKE EFFECT"
380    LET S1=1
390    REM END GOSUB TEST
400    LET I2=I2-1
410    LET I2=I2+C2
420 NEXT I1
430 PRINT "LOOP EXITED"
450 GOSUB 6000
490 LET M$="  OK  "
500 IF T1=T2 THEN 530
510 LET M$="FAILED"
520 LET S1=1
530 PRINT
540 PRINT "NO. TIMES THROUGH LOOP:"
550 PRINT "SHOULD BE: ";T2;"     ACTUAL: ";T1;"    RESULT: ";M$
560 PRINT
570 IF S1=0 THEN 600
580 PRINT "*** TEST FAILED ***"
590 GOTO 610
600 PRINT "*** TEST PASSED ***"
610 PRINT
620 PRINT "               END TEST."
630 PRINT
640 GOTO 690
650 REM SUBROUTINE FROM FIRST SECTION
660 LET T9=9
670 LET I1=I1-1
680 RETURN
690 REM END OF CALLED-FROM-FOR-BLOCK SUBROUTINE
700 PRINT "SECTION 46.2: FOR-LOOPS WITH SAME CONTROL-VARIABLE"
710 PRINT "        NESTED DYNAMICALLY WITH GOSUB."
720 PRINT
730 PRINT "THIS SECTION TESTS THAT A GOSUB ROUTINE CAN BE EXECUTED"
740 PRINT "FROM WITHIN A FOR-BLOCK AND THAT THE SUBROUTINE MAY ITSELF"
750 PRINT "CONTAIN A FOR-BLOCK. IF THE TWO FOR-BLOCKS USE THE SAME"
760 PRINT "CONTROL-VARIABLE, THE ORIGINAL VALUE IS LOST."
770 PRINT
780 PRINT "               BEGIN TEST."
790 LET A1=8
800 LET B1=-5
810 LET C1=-3
820 LET T2=1
830 LET T4=2
840 PRINT
850 PRINT "CONTROL VARIABLE:"
860 PRINT "SHOULD BE","ACTUAL","RESULT"
870 LET A2=A1
880 LET B2=B1
890 LET C2=C1
900 LET I2=A2
910 REM S1 IS ERROR SWITCH
920 LET S1=0
930 REM T1 IS LOOP COUNT
940 LET T1=0
950 PRINT "ENTERING OUTER LOOP"
960 FOR I1=A1 TO B1 STEP C1
970    LET T1=T1+1
990    GOSUB 6000
1030    GOSUB 1360
1040    LET I2=I2+C2
1050 NEXT I1
1060 PRINT "OUTER LOOP EXITED"
1080 GOSUB 6000
1120 LET M$="  OK  "
1130 IF T3=T4 THEN 1160
1140 LET M$="FAILED"
1150 LET S1=1
1160 PRINT
1170 PRINT "NO. TIMES THROUGH INNER LOOP:"
1180 PRINT "SHOULD BE: ";T4;"     ACTUAL: ";T3;"   RESULT: ";M$
1190 PRINT
1200 LET M$="  OK  "
1210 IF T1=T2 THEN 1240
1220 LET M$="FAILED"
1230 LET S1=1
1240 PRINT
1250 PRINT "NO. TIMES THROUGH OUTER LOOP:"
1260 PRINT "SHOULD BE: ";T2;"     ACTUAL: ";T1;"   RESULT: ";M$
1270 PRINT
1280 IF S1=0 THEN 1310
1290 PRINT "*** TEST FAILED ***"
1300 GOTO 1320
1310 PRINT "*** TEST PASSED ***"
1320 PRINT
1330 PRINT "               END TEST."
1340 PRINT
1350 GOTO 1570
1360 REM SUBROUTINE FROM SECOND SECTION
1370 LET I2=-10
1380 REM T3 IS LOOP COUNT
1390 LET T3=0
1400 PRINT "ENTERING INNER LOOP"
1410 FOR I1=-10 TO -7 STEP 2
1420    LET T3=T3+1
1440    GOSUB 6000
1480    LET I2=I2+2
1490 NEXT I1
1500 PRINT "INNER LOOP EXITED"
1520 GOSUB 6000
1560 RETURN
1570 REM END OF CALLED-FROM-FOR-BLOCK SUBROUTINE
1580 PRINT
1590 PRINT "SECTION 46.3 CONTROL-STATEMENT JUMPS OUT OF FOR-BLOCK."
1600 PRINT
1610 PRINT "THIS SECTION TESTS THAT YOU CAN JUMP OUT OF A FOR-BLOCK"
1620 PRINT "AND THAT THE CONTROL-VARIABLE RETAINS ITS VALUE WHEN"
1625 PRINT "THIS HAPPENS."
1630 PRINT
1640 PRINT "             BEGIN TEST."
1650 PRINT
1655 LET S1=0
1660 LET A1=33
1670 LET B1=66
1680 LET C1=4
1690 LET I2=A1
1700 LET T2=8
1703 PRINT "LOOP IS: FOR I1=";A1;" TO ";B1;" STEP ";C1
1707 PRINT
1710 PRINT "CONTROL VARIABLE:"
1720 PRINT "SHOULD BE","ACTUAL","RESULT"
1740 LET T1=0
1750 FOR I1=A1 TO B1 STEP C1
1760   LET T1=T1+1
1770   GOSUB 6000
1780   IF I2 < 60 THEN 1790
1785   GO TO 1850
1790   LET I2=I2+C1
1800 NEXT I1
1810 PRINT "NORMAL EXIT FROM FOR-BLOCK: INCORRECT."
1820 LET S1=1
1830 GOTO 1855
1850 PRINT "JUMPED OUT OF LOOP"
1855 GOSUB 6000
1860 LET M$="  OK  "
1870 IF T1=T2 THEN 1900
1880 LET M$="FAILED"
1890 LET S1=1
1900 PRINT
1910 PRINT "NO. TIMES THROUGH LOOP:"
1920 PRINT "SHOULD BE: ";T2;"     ACTUAL: ";T1;"     RESULT: ";M$
1930 PRINT
1940 PRINT "--------------------------------------"
1950 PRINT
2000 LET A1=7
2010 LET B1=7
2020 LET C1=0
2030 LET I2=A1
2040 LET T2=5
2050 PRINT "LOOP IS: FOR I1=";A1;" TO ";B1;" STEP ";C1
2060 PRINT
2070 PRINT "CONTROL VARIABLE:"
2080 PRINT "SHOULD BE","ACTUAL","RESULT"
2090 LET T1=0
2100 FOR I1=A1 TO B1 STEP C1
2110   LET T1=T1+1
2120   GOSUB 6000
2130   IF T1 > 4.5 THEN 2190
2140   LET I2=I2+C1
2150 NEXT I1
2160 PRINT "NORMAL EXIT FROM FOR-BLOCK: INCORRECT."
2170 LET S1=1
2180 GOTO 2200
2190 PRINT "JUMPED OUT OF LOOP"
2200 GOSUB 6000
2210 LET M$="  OK  "
2220 IF T1=T2 THEN 2250
2230 LET M$="FAILED"
2240 LET S1=1
2250 PRINT
2260 PRINT "NO. TIMES THROUGH LOOP:"
2270 PRINT "SHOULD BE: ";T2;"     ACTUAL: ";T1;"    RESULT: ";M$
2280 PRINT
3000 IF S1=0 THEN 3030
3010 PRINT "***  TEST FAILED  ***"
3020 GOTO 3040
3030 PRINT "***  TEST PASSED  ***"
3040 PRINT
3050 PRINT "               END TEST."
3060 PRINT
3070 PRINT "END PROGRAM 46"
3080 STOP
6000 REM SUBROUTINE TO CHECK THAT I1=I2
6010 LET M$="  OK  "
6020 IF I1=I2 THEN 6050
6030 LET M$="FAILED"
6040 LET S1=1
6050 PRINT I2,I1,M$
6060 RETURN
6070 END
