Google
 

Trailing-Edge - PDP-10 Archives - decus_20tap1_198111 - decus/20-0024/tutr08.bas
There are 2 other files named tutr08.bas in the archive. Click here to see a list.
00100REM   TUT8
00120PRINT"O.K., WE'LL TRY A PROBLEM: REQUIRED, COMPUTE SUCCESSIVE VALUES"
00130PRINT"OF U*(U+1)^2 FOR UNIFORMLY INCREASING 'U' VALUES, BUT LIMITING"
00140PRINT"U*(U+1)^2 TO 10 OR LESS. THE COMPUTER WILL DECIDE HOW MANY 'U'"
00150PRINT"VALUES IT WILL USE. IT WILL KEEP INCREASING 'U' BY 'DELTA U'"
00160PRINT"UNTIL U*(U+1)^2 REACHES 10, THEN STOP. THE PROGRAM SHOWN "
00170PRINT"BELOW WILL ACCOMPLISH THIS."
00180PRINT
00190PRINT"     100 LET U=0"
                                                     00200PRINT"     110 PRINT U,U*(U+1)^2"
00210PRINT"     120 LET U=U+1"
00220PRINT"     130 IF U*(U+1)^2<=10 THEN 110"
00230REM
00240PRINT"     140 END"
00250PRINT
00260PRINT"STUDY THE PROGRAM AND SEE IF YOU CAN TELL ME WHAT LINE NUMBER IS"
00270PRINT"THE BEGINNING OF THE LOOP. WHICH WOULD YOU SAY";
00280INPUTL
00290PRINT
00300IFL=110THEN 330
00310PRINT"TRY ANOTHER NUMBER. WHICH ONE IS IT";
00320GOTO 280
00330PRINT"FINE. AND WHICH IS THE LAST LINE IN THE LOOP";
00340INPUTT
00350IFT=130THEN 380
00360PRINT"STUDY THE PROGRAM AND TRY AGAIN. WHICH ONE";
                       00370GOTO 340
00380PRINT"THAT'S THE ONE. NOTICE WE USED A 'DELTA U' OF UNITY (LINE 120);"
00390PRINT"WE COULD HAVE USED OTHER INCREMENTAL VALUES, WHICH WOULD HAVE"
00400PRINT"CHANGED THE NUMBER OF TIMES THROUGH THE LOOP. HERE ARE THREE "
00410PRINT"OUTPUTS BASED ON DIFFERENT VALUES OF 'DELTA U' SHOWN IN LINE 120:"
00420PRINT
00430PRINT"FOR '120 LET U=U+1' WE GET:        FOR '120 LET U=U+.2' WE GET:"
00440PRINT
00450PRINT"     U        U*(U+1)^2                  U       U*(U+1)^2"
00460PRINT"     0              0                   0              0"
             00470PRINT"     1              4                   .2             .288"
00480PRINT"                                        .4             .784"
00490PRINT"FOR '120 LET U=U+.5' WE GET:            .6             1.536"
00500PRINT"                                        .8             2.592"
00510PRINT"     0              0                   1.             4."
00520PRINT"     .5             1.125               1.2            5.808"
00530PRINT"     1              4                   1.4            8.064"
00540PRINT"     1.5            9.375"
                                           00550PRINT
00560PRINT"IN EACH CASE, 'U' IS THE LEFT-HAND COLUMN AND 'U*(U+1)^2' IS THE"
00570PRINT"RIGHT-HAND COLUMN. NOTICE - THE LARGEST NUMBER IN THE RIGHT-HAND"
00580PRINT"COLUMN IS NEVER OVER 10. THE COMPUTER HAS SEEN THAT ONE MORE 'U'"
00590PRINT"WOULD BE TOO MUCH, AND HAS TAKEN ACTION TO HALT THE LOOP."
00600PRINT
00610PRINT"ANOTHER WAY TO 'LOOP' USES AN INSTRUCTION REQUIRING A PREDETERMINED"
00620PRINT"NUMBER OF LOOPS - I.E., THE COMPUTER IS INSTRUCTED EXACTLY HOW"
00630PRINT"MANY ITERATIONS IT IS TO MAKE. HERE IS AN EXAMPLE:"
                  00640PRINT
00650PRINT"     160 FOR J=2 TO 2.5 STEP .1"
00660PRINT
00670PRINT"HOW WOULD YOU ANSWER THIS: TRUE OR FALSE: 'J' VALUES CONTROL"
00680PRINT"THE NUMBER OF ITERATIONS. (USE: 1=TRUE, 0=FALSE) ANSWER..";
00690INPUTJ
00700PRINT
00710IFJ=1THEN 740
00720PRINT"YOU SHOULD HAVE SAID 'TRUE'. YOU SEE, 'J' IS THE COUNTER, AND"
00730GOTO 750
00740PRINT"YOU'RE RIGHT. THE 'J' VALUE WILL BE USED TO COUNT THE LOOP."
00750PRINT"ITS STARTING VALUE WILL BE '2'. ITS MAXIMUM VALUE WILL BE..";
00760INPUTJ1
00770PRINT
00780	IF J1=2.5 THEN 810
00790PRINT"NO - BUT ITS MAXIMUM VALUE IS SHOWN IN THE STATEMENT. IT IS..";
00800GOTO 760
00810PRINT"GOOD. BUT IT MAY END UP SOMEWHAT LESS, BECAUSE OF THE SIZE OF"
00820PRINT"THE INCREMENT (CHANGE IN 'J'). WHAT INCREMENT IS SHOWN....";
00830INPUTI
00840PRINT
00850IFI=.1THEN 880
00860PRINT"THAT'S NOT IT, BUT THE STATEMENT TELLS. HOW MUCH IS IT....";
00870GOTO 830
00880PRINT"YOU OBVIOUSLY UNDERSTAND THE STATEMENT, AND PROBABLY REALIZE"
00890PRINT"THAT '160' IS THE STATEMENT (OR LINE) NUMBER, 'FOR' MEANS"
00900PRINT"'STARTING VALUE' TO THE MACHINE, 'TO' SAYS 'MAXIMUM VALUE',"
00910PRINT"AND 'STEP' MEANS 'INCREMENT'. "
00920PRINT
00930PRINT"NOW WE HAVE ONE MORE OBSTACLE. THE COMPUTER KNOWS WHERE THE"
00940PRINT"LOOP STARTS (AT LINE 160) AND EVERYTHING ELSE ABOUT IT EXCEPT"
00950PRINT"WHERE IT STOPS - I.E., WHAT THE LAST INSTRUCTION IN THE LOOP "
00960PRINT"IS. DO YOU THINK (1) 'LAST LINE' OR (2) 'NEXT J' OR (3) 'NEW J'"
00970PRINT"IS THE CORRECT LAST INSTRUCTION (TYPE CHOICE NUMBER ONLY)....";
00980INPUTN
00990PRINT
01000IFN=2THEN 1030
01010PRINT"WELL, MAYBE THAT WAS TOO TRICKY. IT SHOULD BE 'NEXT J', AND WE"
   01020GOTO 1040
01030PRINT"THAT'S THE ONE, ALL RIGHT. THE WORD 'NEXT' IS THE CLUE. SO WE"
01040PRINT"PUT A LINE NUMBER ON IT WHICH SEQUENCES IT AS THE LAST LINE OF"
01050PRINT"THE LOOP. THE COMPUTER THEN 'BACKTRACKS' TO THE BEGINNING OF"
01060PRINT"THE LOOP (LINE 160 HERE) AND 'LOOPS' UNTIL'J' SAYS TO STOP."
01070PRINT
01080PRINT"FOR THE PREVIOUS EXAMPLE, SUPPOSE WE WANTED 4 VALUES, REGARDLESS"
01090PRINT"OF THE FUNCTION'S SIZE. LET'S COUNT WITH 'C'. WE'LL WRITE:"
01100PRINT
01110PRINT"     100 LET U=0"
01120PRINT"     110 FOR C=1 TO 4"
                                               01130PRINT"     120 PRINT U,U*(U+1)^2"
01140PRINT"     130 LET U =U+.2"
01150PRINT"     140 NEXT C"
01160PRINT"     150 END"
01170PRINT
01180PRINT"WHEN 'STEP' IS OMITTED (LINE 110) THE INCREASE (IN 'C') IS 1."
01190PRINT"SO NOW WE HAVE LOOKED AT TWO WAYS TO ITERATE - THE 'IF' LOOP"
01200PRINT"AND THE 'FOR' LOOP. WE'LL BE SEEING MORE OF THEM IN THE FUTURE."
01202PRINT
01204PRINT
01210PRINT"BEFORE WE BRING THIS LESSON TO A CLOSE, I'D LIKE TO INTRODUCE"
01220PRINT"YOU TO ONE OF THE USEFUL FEATURES OF YOUR TELETYPE TERMINAL."
01230PRINT"NOTICE THE PAPER TAPE UNIT TO THE LEFT OF YOUR TELETYPE. THIS"
       01240PRINT"PERMITS YOU TO EITHER PUNCH OR READ PAPER TAPE IN CONJUNCTION"
01250PRINT"WITH YOUR PROGRAM. YOU 'READ IN' PAPER TAPE BY INSERTING IT IN"
01260PRINT"THE READER (FAR LEFT) AND TYPING 'TAPE' IN RESPONSE TO SYSTEM. I'LL"
01270PRINT"TYPE 'PROGRAM NAME' TO WHICH YOU RESPOND WITH A 6 CHARACTER"
01280PRINT"OR LESS NAME OF YOUR CHOICE. REMEMBER TO DEPRESS THE RETURN"
01290PRINT"BUTTON TO TELL THE COMPUTER TO LOOK AT THE NAME. "
01292PRINT
01294PRINT
01300PRINT"I'LL THEN TELL YOU TO TYPE X-ON(CONTROL AND Q KEY) AND START THE TAPE."
01310PRINT"THE TAPE WILL BEGIN TRANSMITTING AND WHEN COMPLETED YOU"
01320PRINT"SHOULD THEN TYPE X-OFF (CONTROL AND S KEY)"
01330PRINT" THEN DEPRESS THE RETURN KEY. THE COMPUTER WILL SAVE YOUR "
01340PRINT"FILE AND RETURN YOU TO SYSTEM. YOU MAY THEN CALL BASIC AND"
01345PRINT"RETRIEVE THE FILE BY THE NAME THAT YOU PROVIDED. "
01350PRINT"WE'LL WORK THIS OUT IN MORE DETAIL IN A FUTURE LESSON."
01360PRINT"    THE NEXT LESSON IS 'TUTR09*'"
01370END