|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 138112 (0x21b80) Types: TextFile Names: »D53«
└─⟦1e8064b49⟧ Bits:30005867/disk07.imd Dokumenter (RCSL m.m.) └─⟦this⟧ »D53«
F_ R_C_ _B_A_S_I_C_/_C_O_M_A_L_ A_ _S_t_r_u_c_t_u_r_e_d_ _E_d_u_c_a_t_i_o_n_a_l_ _L_a_n_g_u_a_g_e_ P_R_O_G_R_A_M_M_I_N_G_ _G_U_I_D_E_ A/S REGNECENTRALEN First Edition Development Division January 1979 Documentation Department RCSL 42-i 1203\f F_Authors: Tove Ann Aris Keywords: RC 8000,RC BASIC, RC COMAL, Programming Guide Abstract: This guide describes the RC BASIC language implemented for RC 8000. Copyright A/S Regnecentralen, 1979 Printed by A/S Regnecentralen, Copenhagen\f F_ F_O_R_E_W_O_R_D_ RC BASIC/COMAL is a structured educational language, implemented by A/S Regnecentralen to run on RC 8000. The COMAL language, which was designed by Børge Christensen, Government Teachers> College, Tønder, Denmark, in collaboration with Benedict Løfstedt, Århus University, is incorporated in RC BASIC/COMAL. The implementation was done by Tove Ann Aris, Knud Christensen and Palle Scheef Sørensen. The manual makes extensive use of the RC BASIC Manual for RC 3600/7000 by Stig Mølgaard and Pierze Hazelton.\f C_O_N_T_E_N_T_S_ 1 INTRODUCTION Page11 1.1 General information11 1.2 RC BASIC programs11 1.3 ESCape key12 1.4 Descriptions of statements, commands, and functions13 1.5 Formats used in descriptions14 2 RC BASIC ARITHMETIC17 2.1 Numbers17 2.2 Internal representation of numbers17 2.3 Variables18 2.4 Arrays18 2.4.1 Array elements18 2.4.2 Declaring an array19 2.5 Expressions19 2.5.1 Numeric expressions19 2.5.2 Arithmetic operators19 2.5.2.1 DIV operator20 2.5.2.2 MOD operator20 2.5.3 Priorities of arithmetic operators during program execution20 2.5.4 AND, OR, and NOT operators21 2.5.5 Relational expressions22 2.5.6 Relational operators22 2.5.7 Priorities of arithmetic, Boolean, and relational operators23 2.5.8 String expressions23 3 RC BASIC STATEMENTS 24 3.1 BYE 24 3.2 CASE-WHEN-ENDCASE 24 3.3 CHAIN 30 3.4 DATA 32 3.5 DEF 33 3.6 DELAY 35 3.7 DIGITS36 3.8 DIM 36 3.9 END 39 3.10 ENTER 40\f 3.11 EXEC Page 40 3.12 FOR-NEXT 41 3.13 GOSUB and RETURN 45 3.14 GOTO 46 3.15 IF-THEN 47 3.16 IF-THEN-ENDIF 49 3.17 IF-THEN-ELSE-ENDIF 51 3.18 INPUT53 3.19 LET 56 3.20 LOWBOUND 57 3.21 NEW 58 3.22 ON-ERR 58 3.23 ON-ESC 59 3.24 ON-GOTO/GOSUB 62 3.25 PAGE 63 3.26 PRINT 64 3.27 PRINT USING 68 3.28 PRINTDATE 76 3.29 PRINTEPS 77 3.30 PROC-ENDPROC 78 3.31 RANDOMIZE80 3.32 READ 81 3.33 REM 82 3.34 REPEAT-UNTIL 83 3.35 RESTORE 85 3.36 SAVE 86 3.37 STOP 87 3.38 TAB 88 3.39 TAB(X) function 89 3.40 WHILE-ENDWHILE 90 4 RC BASIC FUNCTIONS 93 4.1 Introduction 93 4.2 ABS(X) 94 4.3 ATN(X) 94 4.4 COS(X) 95 4.5 EXP(X) 95 4.6 FNa(d) 96 4.7 INT(X) 96 4.8 LOG(X) 97 4.9 RND(X) 97 4.10 SGN(X)100 4.11 SIN(X)100 4.12 SQR(X)101 4.13 SYS(X)101 4.14 TAN(X)103\f 5 STRING INFORMATIONPage104 5.1 String concept104 5.1.1 String literals 104 5.1.2 String variables 104 5.1.3 Dimensioning string variables 105 5.1.4 Substrings 105 5.1.5 Assigning values to string variables 106 5.1.6 Concatenation of strings 106 5.1.7 Relational string expressions 108 5.1.8 String arrays 109 5.2 CHR(X) function 110 5.3 LEN(X<) function 111 5.4 ORD(X<) function 112 6 MATRIX MANIPULATION 114 6.1 Matrix operations114 6.2 Dimensioning matrices114 6.3 Matrix assignment statement115 6.4 Matrix addition/subtraction statement116 6.5 Matrix multiplication statement118 6.6 DET(X) function120 6.7 MAT CON statement121 6.8 MAT IDN statement122 6.9 MAT INPUT statement124 6.10 MAT INV statement124 6.11 MAT PRINT statement126 6.12 MAT READ statement128 6.13 MAT SOLVE statement129 6.14 MAT TRN statement129 6.15 MAT ZER statement130 7 FILENAMES, DISC RESOURCES AND RELATED COMMANDS132 7.1 Introduction132 7.2 CLAIM 132 7.3 LOOKUP133 7.4 NEWCLAIM134 7.5 SCANCLAIM134 7.6 SCOPE 135 7.7 SEARCH 136 8 FILES AND RELATED STATEMENTS 137 8.1 Introduction137\f 8.1.1 Disc files and devicespage137 8.1.2 Standard devices and reserved names137 8.1.3 Block sizes138 8.1.4 Filenames and file sizes138 8.1.5 How files are used138 8.1.6 Random access files139 8.1.7 Sequential access files139 8.2 CHANGESIZE139 8.3 CLOSE FILE140 8.4 COPY141 8.5 CREATE141 8.6 DELETE142 8.7 DIGITS FILE143 8.8 EOF(X) function143 8.9 INPUT FILE144 8.10 MAT INPUT FILE145 8.11 MAT PRINT FILE 145 8.12 MAT READ FILE146 8.13 MAT WRITE FILE 146 8.14 OPEN FILE 147 8.15 PAGE FILE149 8.16 PRINT FILE150 8.17 PRINT FILE USING151 8.18 PRINTDATE FILE151 8.19 PRINTEPS FILE152 8.20 READ FILE153 8.21 RENAME154 8.22 TAB FILE155 8.23 WRITE FILE156 9 SYSTEM COMMANDS158 9.1 Introduction158 9.2 Command to delete program statements158 9.3 AUTO160 9.4 BATCH/BATCH "LPT" 162 9.5 BYE162 9.6 CON/CONL163 9.7 DISPLAY165 9.8 ENTER165 9.9 EOJ166 9.10 LIST167 9.11 LOAD168\f 9.12 MESSAGEPage169 9.13 NEW170 9.14 PUNCH 171 9.15 RENUMBER 173 9.16 RUN/RUNL 175 9.17 SAVE 177 9.18 SCRATCH 179 9.19 SIZE 180 9.20 TIME 180 APPENDICES A ERROR MESSAGES 181 A.1 Introduction 181 A.2 Error messages182 A.3 I/O and File related error messages189 A.4 Error messages form scope and newclaim 195 B BATCH MODE AND PROGRAMMING ON MARK-SENSE CARDS 197 B.1 Batch jobs 197 B.2 Mark-sense cards 199 B.2.1 STATEMENT NUMBER 200 B.2.2 STATEMENT 1201 B.2.3 STATEMENT 2 202 B.2.4 FORMULA203 B.2.4.1 Even numbered columns203 B.2.4.2 Odd numbered columns203 B.2.4.3 Writing characters204 B.3 Batch mode207 B.3.1 BATCH/BATCH "LPT" command 207 B.3.2 Illegal statements and commands207 B.3.3 Time limit on jobs208 B.3.4 ESCape key208 B.3.5 Return to interactive mode208 B.4 EOJ command209 B.5 SCRATCH command209 B.6 TIME command210 C OTHER INTERACTIVE USES OF RC BASIC211 C.1 Commands derived from RC BASIC statements211 C.2 Desk calculator functions212 C.3 Program debugging 212 C.4 File input/output 213\f D ASCII CHARACTER SET214 D.1 ASCII characters with their decimal and octal values214 D.2 Output of non-printing characters215 E RESERVED WORDS216 F SUMMARY OF STATEMENTS, COMMANDS, AND FUNCTIONS217 F.1 RC BASIC statements (Chapter 3)217 F.2 RC BASIC functions (Chapter 4)223 F.3 String functions (Chapter 5)225 F.4 Matrix statements (Chapter 6)225 F.5 Filenames, Disc Resources and Related Commands (Chapter 7) 227 F.6 File statements (Chapter 8)228 F.7 System commands (Chapter 9)231 F.8 Batch mode commands (Appendix B)234 G OPERATION AND INSTALLATION 235 G.1 Start of Basic235 G.2 Operators commands236 G.2.1 KILL 236 G.2.2 LOCK 237 G.2.3 UNLOCK 237 G.3 Close of Basic237 G.4 Filerouter Operating Guide 237 G.5 Installation 242 INDEX 244 \f F_1 I_N_T_R_O_D_U_C_T_I_O_N_ 1.1 G_e_n_e_r_a_l_ _i_n_f_o_r_m_a_t_i_o_n_ The RC BASIC programming language provides facilities for: Writing structured programs. Executing programs in interactive mode. Running jobs in batch mode. Performing file input/output. Performing matrix operations. Manipulating strings. Formatting output. Performing desk calculator functions. RC BASIC runs under the RC operating system S. This programming guide describes the syntax and semantics of RC BASIC statements, commands, and functions. Those who have access to terminals can use RC BASIC in inter- active mode, but it is also possible to execute programs written on mark-sense cards in batch mode (see App. B). l.2 R_C_ _B_A_S_I_C_ _p_r_o_g_r_a_m_s_ An RC BASIC program consists of a number of statements. Each statement begins with a line number, in the range 1 to 9999, which determines the order in which the statement will be executed. The rest of the statement is made up of one or more RC BASIC words (see below), with or without arguments. Each statement is written on a separate line. The user terminates each statement line by pressing the RETURN key. This generates an automatic line feed in addition to the carriage return. (Note: The "carriage return" separator referred to in this guide is the RETURN key, not the ASCII character Carriage Return). If the user discovers a typing error b_e_f_o_r_e_ he has pressed the RETURN key, he can delete the last character typed by pressing the RUBOUT key (repeatedly, if need be) or delete the entire line by pressing the ESCape key. \f Some RC BASIC words, such as END, STOP, or CLOSE, can be used alone to perform an operation; others require one or more arguments, on which the operations are performed. Thus the word READ, for example, cannot be used alone; READ must have at least one argument, viz. the name of a variable to which a value is to be assigned (e.g. READ PRICE). The user may enter program statements in any order. The system will arrange them by ascending line numbers. When a program is run, the statements are executed one by one in ascending line number order, usually beginning with the lowest numbered statement. The sequential execution of state- ments may be interrupted by a "control transfer statement," such as ENDWHILE, EXEC, ENDPROC, or GOTO. Many of the RC BASIC statements, which are described in Chapters 3, 6, and 8, may also be used as keyboard commands (see App. C). When a statement is used as a command, it is entered without a preceding line number and terminated by pressing the RETURN key, whereupon the system executes it immediately. Still other RC BASIC words can only be used alone, i.e. they cannot be part of a statement, but are used solely as commands. LIST and RUN are examples of such words. When a program has been entered, it will remain in core memory until the user clears it by means of a NEW command. New statement lines can be inserted anywhere in a program. Existing statements can be deleted, by typing the statement line number and pressing the RETURN key, or corrected, simply by entering a new statement with the same line number. The currently loaded program can be executed by means of a RUN/RUNL command. T_ 1.3 E_S_C_a_p_e_ _k_e_y_ Pressing the ESCape key during program execution will cause &_ interruption of the program, unless an ON-ESC statement has been executed (see Ch. 3). Control will be returned to interactive mode, and the system will output the following on the user>s\f terminal: T_ STOP AT xxxx' &_ * where xxxx' is the line number of the statement at which the program was interrupted. The asterisk (*) prompt indicates that the user may enter a command or a program statement. Program execution can be resumed by means of a CON/CONL or RUN/RUNL line no.' command. Pressing the ESCape key on an idle terminal (e.g. after system start-up or a BYE command) will place the terminal in inter- active mode. When a terminal is in batch mode, the ESCape key has a special function (see App. B). T_1.4 D_e_s_c_r_i_p_t_i_o_n_s_ _o_f_ _s_t_a_t_e_m_e_n_t_s_,_ _c_o_m_m_a_n_d_s_,_ _a_n_d_ _f_u_n_c_t_i_o_n_s_ Descriptions of the statements, commands, and functions in the RC BASIC language will be found in Chapters 3 through 9. These descriptions have the following form: x.y R_C_ _B_A_S_I_C_ _W_O_R_D_ Format Use Remarks Example &_ where x.y : Chapter.Section RC BASIC WORD : One or more reserved RC BASIC words Format : The generalized format (syntax) of the statement, command, or function. This format, which is explained in detail below, must be used when the statement, command, or function is entered from the\f terminal, otherwise an error message (usually 0002: SYNTAX ERROR) will result. Use : Indicates whether the RC BASIC word is used as a statement, command, or function, and describes the operation or operations which it performs. Remarks : Contains remarks concerning the use of the statement, command, or function, including rules, precautions, program operation, and the like. Example : The use of most of the statements, commands, and functions is illustrated by one or more examples, which usually consist of small programs, followed by the output produced when the program was executed. As many of the programs were listed on the line printer, and the resulting output was directed to the line printer, the commands used (viz. LIST "<LPT" and RUNL) do not appear in these examples. In a few examples, for clarity"s sake, the text entered by the user is underlined and followed by the symbol to denote that the user has terminated the line by pressing the RETURN key, e.g. ? 5_,_6_,_7_,_8_ _ _ T_ 1.5F_o_r_m_a_t_s_ _u_s_e_d_ _i_n_ _d_e_s_c_r_i_p_t_i_o_n_s_ Capital letters in the generalized format denote literal entries. &_ Any parentheses should be inserted as indicated. Braces ( ) indicate a choice of the items enclosed. Brackets () indicate that the enclosed items are optional. An ellipsis (...) indicates that the preceding argument may be repeated.\f Several abbreviations are used in the formats to represent common terms. All abbreviations in a format are explained immediately beneath it, while the terms represented are defined in the appropriate chapters of this guide. The most frequently occurring abbreviations are: var' : The name of a numeric variable, with or without subscripts. svar' : The name of a string variable, with or without subscripts. expr' : A numeric, relational (Boolean), orstring expression (see Ch. 2). slit' : A string literal (string constant), i.e. a sequence of characters enclosed within quotation marks ("). val' : A numeric constant. line no.' : A statement line number in the range 1 to 9999. statements' : One or more RC BASIC statements. mvar' : The name of a matrix variable. ldname' : The name of a logical disc. filename' : The name of a disc file or a device. device' : The name of a device. file' : A numeric expression which evaluates to a number in the range -1 to maxfile (the number of a user file). -1: current input/output. \f T_ As an example, consider the generalized format of the PRINT statement (see Ch. 3): expr' expr' ;slit' , slit' , PRINT svar' ; svar' ... ; &_1 1 25 56 7 7 6 234 43 The PRINT statement begins with the word PRINT. As PRINT is frequently used, one can write a semicolon (;) instead of the word PRINT. This is indicated by the pair of braces 1-1. The pair of brackets 2-2 indicates that the PRINT statement need not have an argument. PRINT may optionally (brackets 3-3) be followed by a comma or a semicolon (braces 4-4). An argument may be of the type expr', slit', or svar', as indicated by the pair of braces 5-5. If there is more than one argument (brackets 6-6 and the ellipsis), the arguments should be separated by a comma or a semicolon (braces 7-7).\f F_ 2 R_C_ _B_A_S_I_C_ _A_R_I_T_H_M_E_T_I_C_ 2.1 N_u_m_b_e_r_s_ An RC BASIC number may be in the range: -1.6 * 10UUU-616DDD n 1.6 * 10UUU616DDD Numbers may be expressed as integers, as floating-point numbers, the constants TRUE and FALSE or in exponential form (E-type notation).TRUE has the value 1 and FALSE the value 0. In the conversion of numeric data, e.g. by a PRINT statement (see Ch. 3), any floating-point or integer number that contains six digits or less is formatted without using exponential form. A floating-point or integer number that requires more than six digits is printed in the following E-type notation: sign'n.nnnnnEsign'XX where n.nnnnn is an unsigned number carried to five decimal places with trailing zeroes suppressed, E means "times 10 to the power of," and XX represents an unsigned exponential value. N_u_m_b_e_r_ O_u_t_p_u_t_ _f_o_r_m_a_t_ 2,000,000 2E+06 108.999 108.999 .0000256789 2.56789E-05 24E10 2.4E+11 T_ 2.2 I_n_t_e_r_n_a_l_ _r_e_p_r_e_s_e_n_t_a_t_i_o_n_ _o_f_ _n_u_m_b_e_r_s_ Internally, floating-point numbers are stored in two consecutive 24-bit words having the form: _0_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _2_3_ S M _ _ _ _ _ _ _ _ _ _ _ _ __________MANTISSA ____________S_ _ _ _C_______ &_ 24 36 37 47 \f where: S is the sign of the exponent (0 = positive, 1 = negative); the mantissa is a normalized 35 digits fraction (bit 0 contains the sign of the mantissa) and C is the exponent. T_2.3 V_a_r_i_a_b_l_e_s_ A numeric variable name (shown in the statement descriptions &_ as var') consists of a single letter followed by from 0 to 7 T_ digits or letters, for example: L_e_g_a_l_ _n_a_m_e_s_ I_l_l_e_g_a_l_ _n_a_m_e_s_ I <PRICE INTEREST 6I AMOUNT MEANVALUE PRICE &_ In addition to numeric variables, string variables (shown in the statement descriptions as svar') are also permitted in RC BASIC (see Ch. 5). T_2.4 A_r_r_a_y_s_ An array represents an ordered set of values. Each member of &_ the set is called an array element. An array can have either one or two dimensions. An array name consists of a single letter followed by from 0 to 7 digits or letters. b_2.4.1 A_r_r_a_y_ _e_l_e_m_e_n_t_s_e Each of the elements of an array is identified by the name of the array followed by a parenthesized subscript, for example: ITEMNO(1), ITEMNO(2), ..., ITEMNO(8), ITEMNO(9) &_ For a two-dimensional array, the first number gives the number of the row and the second gives the number of the\f T_ column for each element. Thus the elements of the array C(2,3) would be: C(1,1) C(1,2) C(1,3) &_ C(2,1) C(2,2) C(2,3) b_2.4.2 D_e_c_l_a_r_i_n_g_ _a_n_ _a_r_r_a_y_ e An array must be declared in a DIM statement (see Ch. 3), which gives the name of the array and its dimensions. &_ The lower bound of a dimension is always 1. The upper bound isy a given in the DIM statement, two upper bounds being separated b comma (,). Dimensional information is enclosed in paranthesesnt, T_ immediately following the name of the array in the DIM stateme for example: 5 DIM SET(15), AMOUNT(2,3) 2.5 E_x_p_r_e_s_s_i_o_n_s_ &_ An expression (shown in the statement descriptions as expr') may be composed of parentheses, constants and variables (numeric or string), and functions, linked together by operators. T_b_2.5.1 N_u_m_e_r_i_c_ _e_x_p_r_e_s_s_i_o_n_s_e A numeric expression may be composed of numeric variables and constants and (numeric) functions, linked together by arithmetic operators. T_b_ 2.5.2 A_r_i_t_h_m_e_t_i_c_ _o_p_e_r_a_t_o_r_s_e The arithmetic operators are as follows: + : monadic + ( A+(+B) ) - : monadic - ( A+(-B) ) : exponentiation ( A B ) * : multiplication ( A*B ) / : division ( A/B ) MOD : modulus calculation ( A MOD B ) DIV : integer division ( A DIV B ) + : addition ( A+B ) &_ - : subtraction ( A-B ) The operators +, -, *, /, and are familar to most, but DIV and MOD may require some explanation. \f T_2.5.2.1 D_I_V_ _o_p_e_r_a_t_o_r_. The result of an integer division A DIV B is equ to: SGN(A/B)*INT(INT(ABS(A))/INT(ABS(B))) The SGN(X), INT(X), and ABS(X) functions are described in Chapter 4. E_x_a_m_p_l_e_s_ 11 DIV 4 = +1 x 2 = 2 -11 DIV 4 = -1 x 2 = -2 &_ T_ 2.5.2.2 M_O_D_ _o_p_e_r_a_t_o_r_. The result of a modulus calculation A MOD B is equal to: SGN(A)*INT(ABS(A))-A DIV B*SGN(B)*INT(ABS(B)) &_ The SGN(X), INT(X), and ABS(X) functions are described in Chapter 4. T_ E_x_a_m_p_l_e_s_ 11 MOD 4 = 11 - 2 x 4 = 3 -11 MOD 4 = -11 - (-2) x 4 = -3 &_ T_b_2.5.3 P_r_i_o_r_i_t_i_e_s_ _o_f_ _a_r_i_t_h_m_e_t_i_c_ _o_p_e_r_a_t_o_r_s_ _d_u_r_i_n_g_ _p_r_o_g_r_a_m_ _e_x_e_c_u_t_i_o_n_ _e As a general rule, numeric expressions are evaluated from left &_ to right. The arithmetic operators, however, have different priorities, for which reason the following exceptions to this rule apply: 1. Numeric expressions enclosed within parentheses are always evaluated before non-parenthesized expressions. If expres- sions are nested, the innermost expression is evaluatedfirst. 2. Functions are evaluated next. 3. The priorities of the arithmetic operators are as follows: First: monadic plus and monadic minus Second: exponentiation Third: multiplication, division, modulus calculation, and integer division Fourth: addition and subtraction\f 4. When two operators have the same priority, evaluation proceeds from left to right. T_ The following two examples should help clarify the principles according to which numeric expressions are evaluated. 1 + 2 - 3 x 4 2 DIV 5 + 6 1: 1 + 2 - 3 x 16 DIV 5 + 6 2: 1 + 2 - 48 DIV 5 + 6 3: 1 + 2 - 9 + 6 4: 3 -9 + 6 5: -6 + 6 6: 0 (1 + (2 - 3) x 4 2) DIV 5 + 6 1: (1 + (-1) x 4 2) DIV 5 + 6 2: (1 -1 x 4 2) DIV 5 + 6 3: (1 -1 x 16 ) DIV 5 + 6 4: (1 - 16 ) DIV 5 + 6 5: -15 DIV 5 + 6 6: -3 + 6 7: 3 &_ T_ b_ 2.5.4 A_N_D_,_ _O_R_,_ _a_n_d_ _N_O_T_ _o_p_e_r_a_t_o_r_s_e The operators AND, OR, and NOT are analogous to *, +, and &_ -; but whereas *, +, and - have numeric arguments, AND, OR, and NOT have Boolean arguments. A Boolean argument can have two values: true, corresponding to 1 (or ' 0), and false, corresponding to 0. T_ NOT operates on one argument only, and means logical ne- gation, for example: _ _A_ _ _ _ _ _ _ _ _ _ _ _N_O_T_ _A_ _ TRUE FALSE _F_A_L_S_E_ _ _ _ _ _ _ _ _T_R_U_E_ _ _ &_ \f T_ AND operates on two arguments, and means logical multi- plication (logical and), for example: _ _A_ _ _ _ _ _ _ _ _ _ _ _B_ _ _ _ _ _ _ _ _ _ _ _A_ _A_N_D_ _B____________ FALSE (0) FALSE (0) FALSE (0 x 0 = 0) FALSE (0) TRUE (1) FALSE (0 x 1 = 0) TRUE (1) FALSE (0) FALSE (1 x 0 = 0) _T_R_U_E_ _(_1_)_ _ _ _ _T_R_U_E_ _(_1_)_ _ _ _ _ _T_R_U_E_ _(_1_ _x_ _1_ _=_ _1_)__ _ &_ T_ OR operates on two arguments, and means logical addition (logical or), for example: _ _A_ _ _ _ _ _ _ _ _ _ _ _B_ _ _ _ _ _ _ _ _ _ _ _A_ _O_R_ _B____________ _ FALSE (0) FALSE (0) FALSE (0 + 0 = 0) FALSE (0) TRUE (1) TRUE (0 + 1 = 1) TRUE (1) FALSE (0) TRUE (1 + 0 = 1) _T_R_U_E_ _(_1_)_ _ _ _ _T_R_U_E_ _(_1_)_ _ _ _ _ _T_R_U_E_ _(_1_ _+_ _1_ __'_ _0_)_ _ &_ T_ The priorities of these three operators are: First: NOT Second: AND &_ Third: OR T_ b_ 2.5.5 R_e_l_a_t_i_o_n_a_l_ _e_x_p_r_e_s_s_i_o_n_s_e A relational expression is composed of two expressions of the same type, i.e. both numeric or both string, linked &_ together by a relational operator. T_b_2.5.6 R_e_l_a_t_i_o_n_a_l_ _o_p_e_r_a_t_o_r_s_e The relational operators are as follows: : less than = : less than or equal to = : equal to '= : greater than or equal to ' : greater than &_ ' : not equal to As mentioned above, all relational operators have two arguments. The arguments are compared, and the result of the comparison is always either true or false. Thus the notation 0 X 10\f is illegal, as this would result in a comparison of 0 and X (true or false) followed by a comparison of (true or false) and 10 which is meaningless. The correct notation is: 0 X AND X 10 T_ E_x_a_m_p_l_e_s_ 1 10 is true. 1 ' 10 is false. "JOHN" "PETER" is true (see Ch. 5). 1 10 AND 20 30 is true (1 x 1 = 1). 10 5 OR 2 11 is true (0 + 1 = 1). NOT 1 4 is false. &_ T_b_2.5.7 P_r_i_o_r_i_t_i_e_s_ _o_f_ _a_r_i_t_h_m_e_t_i_c_,_ _B_o_o_l_e_a_n_,_ _a_n_d_ _r_e_l_a_t_i_o_n_a_l_ _o_p_e_r_a_t_o_r_s_ e In compound expressions, the priorities of arithmetic, Boolean, and relational operators are as follows: First: monadic plus and monadic minus Second: exponentiation Third: multiplication, division, modulus calculation, and integer division Fourth: addition and subtraction Fifth: relational operators (', , =, =, '=, ') Sixth: NOT Seventh: AND Eighth: OR T_ b_ 2.5.8 S_t_r_i_n_g_ _e_x_p_r_e_s_s_i_o_n_s_e A string expression (see further Ch. 5) may be any of the following: 1. A string variable, e.g. ANSWER< 2. A string literal, e.g. "PETER" 3. The CHR(X) function, e.g. CHR(65) 4. A concatenation of the above items, e.g. &_ "JOHN SMITH",ADDRESS< \f F_ 3 RC BASIC STATEMENTS 3.1 B_Y_E_ For description, see Chapter 9. 3.2 C_A_S_E_-_W_H_E_N_-_E_N_D_C_A_S_E_ F_o_r_m_a_t_ CASE expr' OF statements-0' WHEN expr' ,expr' ... statements-1' . . . WHEN expr' ,expr' ... statements-n' ENDCASE comment' expr': an expression. statements-0': a block of statements. . . . statements-n': a block of statements. comment': a text comment. U_s_e_ As a statement to execute one of several block of statements depending on the value of an expression. R_e_m_a_r_k_s_ 1. R_u_l_e_s_ a. expr' may be an expression of any kind. b. For every CASE statement there must be at least one corresponding WHEN statement and one ENDCASE statement.\f c. If a block of statements belonging to a CASE construc- tion is entered from outside the construction, the error message 0062: WHEN WITHOUT CASE or 0061: ENDCASE WITHOUT CASE will be output when WHEN or ENDCASE is encountered. T_2. P_r_o_g_r_a_m_ _o_p_e_r_a_t_i_o_n_ a. The expression in the CASE expr' OF statement is evaluated. &_ b. The expressions in the WHEN expr' ,expr' statements are evaluated one by one until a value is found which is equal to the value obtained in step a. If this value is found in the ith WHEN statement, statements-i' is executed. c. Execution continues until a WHEN or ENDCASE statement is encountered; after this, control is transferred to the first statement following the ENDCASE statement. d. If a matching value is not found in step b, statements-0' is executed. If statements-0' is not present, the error message 0059: CASE WITHOUT WHEN, CASE ERROR will be output. T_3. N_e_s_t_e_d_ _c_o_n_s_t_r_u_c_t_i_o_n_s_ CASE-WHEN-ENDCASE constructions may be nested to any depth. &_ 4. The word ENDCASE may be followed by a comment. \f F_ E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 FOR I=1 TO 5 Shows a nested CASE con- 0020 CASE I OFstruction. 0030 PRINT "CASE ERROR - I" 0040 WHEN 1,3+1,6 0050 FOR J=3 TO 5 0060 CASE J OF 0070 PRINT "CASE ERROR - J" 0080 WHEN 3 0090 PRINT "I,J =";I;J 0100 WHEN 4 0110 PRINT "J,I =";J;I 0120 ENDCASE 0130 NEXT J 0140 WHEN 2 0150 PRINT "I =";I 0160 WHEN 3 0170 PRINT "I =";I 0180 ENDCASE 0190 NEXT I 0200 STOP I,J = 1 3 J,I = 4 1 CASE ERROR - J I = 2 I = 3 I,J = 4 3 J,I = 4 4 CASE ERROR - J CASE ERROR - I \f F_ E_x_a_m_p_l_e_ _2_ 0010 DIM MONTH<(10) 0020 FOR MONTHNR=1 TO 13 0030 CASE MONTHNR OF 0040 PRINT "ILLEGAL NUMBER: ";MONTHNR 0050 GOTO 0330 0060 WHEN 1 0070 LET MONTH<="JANUARY"; DAYS=31 0080 WHEN 2 0090 LET MONTH<="FEBRUARY"; DAYS=28 0100 WHEN 3 0110 LET MONTH<="MARCH"; DAYS=31 0120 WHEN 4 0130 LET MONTH<="APRIL"; DAYS=30 0140 WHEN 5 0150 LET MONTH<="MAY"; DAYS=31 0160 WHEN 6 0170 LET MONTH<="JUNE"; DAYS=30 0180 WHEN 7 0190 LET MONTH<="JULY"; DAYS=31 0200 WHEN 8 0210 LET MONTH<="AUGUST"; DAYS=31 0220 WHEN 9 0230 LET MONTH<="SEPTEMBER"; DAYS=30 0240 WHEN 10 0250 LET MONTH<="OCTOBER"; DAYS=31 0260 WHEN 11 0270 LET MONTH<="NOVEMBER"; DAYS=30 0280 WHEN 12 0290 LET MONTH<="DECEMBER"; DAYS=31 0300 ENDCASE 0310 PRINT TAB(10-LEN(MONTH<));MONTH<; 0320 PRINT " HAS";DAYS;"DAYS." 0330 NEXT MONTHNR 0340 STOP \f T_ JANUARY HAS 31 DAYS. FEBRUARY HAS 28 DAYS. MARCH HAS 31 DAYS. APRIL HAS 30 DAYS. MAY HAS 31 DAYS. JUNE HAS 30 DAYS. JULY HAS 31 DAYS. AUGUST HAS 31 DAYS. SEPTEMBER HAS 30 DAYS. OCTOBER HAS 31 DAYS. NOVEMBER HAS 30 DAYS. DECEMBER HAS 31 DAYS. &_ ILLEGAL NUMBER: 13 \f T_ E_x_a_m_p_l_e_ _3_ 0010 DIM ANSWER<(20) 0020 PROC GETANSWR 0030 REM THE PROCEDURE ACCEPTS ONE OF THREE POSSIBLE 0040 REM ANSWERS: YES, NO, OR DON"T KNOW 0050 REPEAT 0060 LET ERROR=0 0070 INPUT ANSWER< 0080 PRINT ANSWER< 0090 CASE ANSWER< OF 0100 PRINT "ERROR, RETYPE" 0110 LET ERROR=1 0120 WHEN "YES" 0130 LET YES=YES+1 0140 WHEN "NO" 0150 LET NO=NO+1 0160 WHEN "DON"T KNOW","DO NOT KNOW" 0170 LET DONTKNOW=DONTKNOW+1 0180 WHEN "END" 0190 LET FINIS=1 0200 ENDCASE 0210 UNTIL NOT ERROR 0220 ENDPROC 0230 REM 0240 REM MAIN PROGRAM 0250 REM PRINT QUESTION, CHECK ANSWER 0260 REM BY MEANS OF THE PROCEDURE 0270 REM GETANSWR 0280 REM 0290 LET FINIS=0; YES=0; NO=0; DONTKNOW=0 0300 REPEAT 0310 PRINT "QUESTION" 0320 EXEC GETANSWR 0330 UNTIL FINIS 0340 PRINT "13'10'10'"," YES"," NO","DON"T KNOW" 0350 PRINT ,YES,NO,DONTKNOW 0360 STOP &_ \f T_ QUESTIONC_o_m_m_e_n_t_ _(_3_)_ NO QUESTIONFor PROC-ENDPROC, YESsee Section 3.26. QUESTION YES QUESTION DO NOT KNOW QUESTION NO QUESTION DON"T KNOW QUESTION NOT ERROR, RETYPE NO QUESTION YESE ERROR, RETYPE YES QUESTION END YES NO DON"T KNOW &_ 3 3 2 T_ 3.3 C_H_A_I_N_ F_o_r_m_a_t_ &_ CHAIN filename' THEN GOTO lineno.' filename': a disc file or a device expressed as a string literal or by means of a variable. line no.': the line number in the program referred to by filename' from which execution is to begin. T_ U_s_e_ As a statement or command to run the SAVEd program referred to by filename' when the CHAIN statement is encountered in the user>s &_ program. \f T_ R_e_m_a_r_k_s_ 1. When a CHAIN statement is encountered in a program, it stops execution of that program, loads a previously SAVEd program (see SAVE, Ch. 9) from the disc file or the device specified by filename', and begins execution of the SAVEd program. 2. If the SAVEd program is on disc, the system searches the logical disc to which the terminal is connected for filename' (see Ch. 8). If filename' is not found, the system outputs the error message 0149: INPUT AREA DOES NOT EXIST. &_ 3. If filename' is found, the user>s currently running program is cleared from core memory and the SAVEd program is loaded into core memory from filename'. If filename' is not found, the current program remains in core memory. 4. The newly loaded program is run from its lowest numbered statement, unless the THEN GOTO line no.' argument is given in the CHAIN statement to specify another line number from which execution is to begin. 5. The CHAIN statement is typically used to divide a large program into smaller programs or to run independent programs from a main program on the basis of conditional statements. 6. CHAIN may also be used as a command, in which case it has the same effect as LOAD (see Ch. 9), i.e. the SAVEd program is loaded, but not executed. 7. When the CHAINed program is executed, it is done without clearing the state of the program. This means that all variables have the values they had, when the program was SAVEd. If a CHAINed program should be exetuted as if the user had started it by means of the command RUN. Then the user must bring the program into "neutral" state before it is SAVEd: 1 STOP ; insert STOP as the first statement RUN ; execute the program 1 ; delete STOP-statement SAVE "filename'" ; SAVE the program \f T_E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 INPUT "SELECT PROGRAM NUMBER : ",NUMBERThe user selects a 0020 CASE NUMBER OF program by typing a 0030 PRINT "ILLEGAL NUMBER" number. 0040 WHEN 1 0050 CHAIN "PROGRAM1" 0060 WHEN 2 0070 CHAIN "PROGRAM2" 0080 WHEN 3 0090 CHAIN "PROGRAM3" &_0100 ENDCASE T_ E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ 0010 DIM NAME<(10) The user selects a 0020 INPUT "SELECT PROGRAM : ",NAME< program by typing its 0030 CHAIN NAME< name, i.e. the name of 0040 END the disc file or the device from which the program is to be CHAINed. &_ T_ 3.4 D_A_T_A_ F_o_r_m_a_t_ val' ,val' DATA slit' ,slit' ... val': a numeric value. slit': a string literal. U_s_e_ As a statement to provide values to be read into variables &_ appearing in READ statements. T_ R_e_m_a_r_k_s_ &_ 1. The DATA statement is non-executable. 2. The values appearing in a DATA statement or statements form a single list. The first element in this list is the first item\f inthe lowest numbered DATA statement. The last element in the list is the last item in the highest numbered DATA statement. 3. Both numbers and string literals may appear in a DATA statement. Each value in a DATA statement list must be separated from the next value by a comma. T_ E_x_a_m_p_l_e_ 100 DATA 1,17,"AB,CD",-1.3E-13 &_ S_e_e_ _f_u_r_t_h_e_r_ _R_E_A_D_ _(_S_e_c_t_._ _3_._3_1_)_._ T_ 3.5 D_E_F_ F_o_r_m_a_t_ DEF FNa'(d') = expr' a': a letter. d': a dummy numeric variable, which may appear in expr'. expr': a numeric expression, which may contain the &_ variable d'. U_s_e_ As a statement to permit the user to define as many as 29 different functions, which can be referenced repeatedly throughout a program. Each function returns a numeric value. R_e_m_a_r_k_s_ 1. The name of the defined function must be the two letters FN followed by a single letter, viz. A, B, ..., Z, @, Ø, orÅ. 2. The dummy variable named in the DEF statement is not related to any variable in the program having the same name; the DEF statement simply defines the function and does not cause any calculation to be carried out. 3. In the function definition, expr' may be any legal numeric expression and may include other user-defined functions. Functions may be nested to a depth of seven.\f 4. Function definition is limited to a single-line DEF statement. Complex functions that require more than one program statement should be constructed as subroutines or procedures. T_ E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ * LIST Calculates 0010 DEF FNP(X)=X 2+2*X+2 P(X) = X 2+2*X+2 for 0020 FOR I=1 TO 5 different values of X. 0030 PRINT FNP(I); 0040 NEXT I * RUN 5 10 17 26 37 END AT 0040 &_* \f T_ E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ * LIST Shows the nesting of 0010 DEF FND(X)=X*SYS(14)/180functions. 0020 DEF FNS(X)=SIN(FND(X)) 0030 DEF FNC(X)=COS(FND(X)) 0040 FOR DEGR=0 TO 45 STEP 5 0050 PRINT DEGR,FNS(DEGR),FNC(DEGR) 0060 NEXT DEGR 0070 STOP * TAB=12 * RUN 0 0 1 5 8.71556E-2 .996195 10 .173648 .984808 15 .258819 .965926 20 .34202 .939693 25 .422618 .906308 30 .5 .866025 35 .573576 .819152 40 .642787 .766045 45 .707107 .707107 STOP AT 0070 &_* T_3.6 D_E_L_A_Y_ F_o_r_m_a_t_ DELAY = expr' expr': a numeric expression, which is evaluated to an integer in the range 0 expr' = 60. U_s_e_ As a statement to interrupt program execution for a specified &_number of seconds. \f R_e_m_a_r_k_s_ 1. expr' is the number of seconds for which the program is stopped. 2. When expr' seconds have passed since the DELAY statement was encountered, program execution will continue from the first statement following the DELAY statement. 3.7 DIGITS F_o_r_m_a_t_ DIGITS =expr' expr': a numeric expression in the range 1=expr'=11 U_s_e_ As a command or statement to specify the number of digits output by a PRINT statement. R_e_m_a_r_k_s_ The default value is 6. E_x_a_m_p_l_e_ DIGITS = 4 T_3.8D_I_M_ F_o_r_m_a_t_ svar'(1')svar'(1') sarray'(n',1' sarray'(n',1') DIM array'(m') , array'(m') ... array'(row',col') array'(row',col') svar': a string variable. l': a numeric expression, which evaluates to the length of a string variable or the length of &_ each element in a string array. sarray': a string array name. n': a numeric expression, which evaluates to the number of elements in a string array. \f array': an array name. m': a numeric expression, which evaluates to the number of the last element in a one-dimensional array. row': a numeric expression, which evaluates to the number of the last row in a two-dimensional array. col': a numeric expression, which evaluates to the number of the last column in a two-dimensional array. T_U_s_e_ As a statement or command to define explicitly the size of one or more numeric variable arrays, string variables or string ar- rays. (For the dimensioning of string variables, see Chapter5). &_ T_R_e_m_a_r_k_s_ 1. A_r_r_a_y_ _e_l_e_m_e_n_t_s_ For the concept of arrays, see Chapter 2. The DIM statement &_ is used to declare the size of an array to be a specified number of elements for each dimension, for example: 10 DIM A(13),B(7,7),C(20,5) Until a value is assigned by the user>s program, the value of all elements in an array is zero. Any variable or expression that is used for a subscript must evaluate to a value in the range lowbound = value = upper bound declared in the DIM statement for example: 15 X=2 20 PRINT B(1,X 2) If the variable or expression subscript does not evaluate to an integer, RC BASIC will convert it using the INT(X) function (see Ch. 4).\f If a subscript evaluates to an integer greater than the upper bound of the dimension for the array or less than the lower bound (as defined by means of the LOWBOUND statement), the error message 0031: SUBSCRIPT ERROR will be output. T_2. R_e_d_i_m_e_n_s_i_o_n_i_n_g_ _a_r_r_a_y_s_ One can redimension a previously defined array during execution of a program by declaring the array in another DIM &_ statement. The total number of elements in the redimensioned array must not exceed the previous total number of elements, for example: T_ 100 DIM A(3,3) . . . 200 DIM A(2,3) . . . 300 DIM A(2,2) The values assigned to elements in the array A(3,3) are re- assigned to elements in the array A(2,3) and then to elements &_in the array A(2,2): T_ 1 2 3 1 2 3 1 2 4 5 6 4 5 6 3 4 7 8 9 A(1,1) = 1 A(1,1)= 1A(1,1) = 1 A(1,2) = 2 A(1,2) = 2 A(1,2) = 2 A(1,3) = 3 A(1,3) = 3 A(2,1) = 3 A(2,1) = 4 A(2,1) = 4 A(2,2) = 4 A(2,2) = 5 A(2,2) = 5 A(2,3) = 6 A(2,3) = 6 A(3,1) = 7 A(3,2) = 8 &_ A(3,3) = 9 \f T_ 3.9 E_N_D_ F_o_r_m_a_t_ END comment' comment': a text comment. &_ U_s_e_ As a statement to terminate execution of the program and to return control to interactive mode. T_R_e_m_a_r_k_s_ 1. RC BASIC includes the END statement, but does not require its &_ use to declare the physical end of a program. If control passes through the last executable statement of the program and if that statement does not change the flow of control, i.e. is not a GOTO or similar statement, then the program will transfer control to interactive mode. 2. Multiple END statements may appear in the same program, and when encountered will terminate execution of the program followed by a prompt (*) output on the user>s terminal. 3. The word END may be followed by a comment. T_E_x_a_m_p_l_e_ *20 PRINT "PROGRAM DONE" *30 GOTO 60 . . . *50 *60 END * RUN PROGRAM DONE END AT 0060 &_* \f T_ 3.10 E_N_T_E_R_ For description, see Chapter 9. &_ T_3.11 E_X_E_C_ F_o_r_m_a_t_ EXEC name' name': the name of a procedure. name' may also be a simple numeric variable. &_ T_U_s_e_ As a statement to execute a procedure defined by PROC-ENDPROC (see Sect. 3.26). &_ T_ R_e_m_a_r_k_s_ 1. R_u_l_e_s_ name' is the name of the procedure to be executed. If name' &_ is a simple numeric variable, it may be assigned a value before the procedure is called; it may also be assigned a new value by the procedure before control is returned to the main program. T_2. P_r_o_g_r_a_m_ _o_p_e_r_a_t_i_o_n_ a. When the EXEC statement is encountered, a search is made &_ for the procedure named name'. b. If name' is not found, the error message 0046: PROCEDURE DOES NOT EXIST will be output. c. The statements in the procedure are executed until an ENDPROC or RETURN statement is encountered. Control is then returned to the first statement following the EXEC statement. E_x_a_m_p_l_e_ See PROC-ENDPROC (Sect. 3.29).\f T_3.12F_O_R_-_N_E_X_T_ F_o_r_m_a_t_ FOR control var' = expr1' TO expr2' STEP expr3' &_ statements' NEXT control var' control var': an unsubscripted numeric variable. expr1': a numeric expression defining the first or initial value of control var'. expr2': a numeric expression defining the terminating value of control var'. expr3': a numeric expression defining the increment added to control var' each time the loop is executed. statements': a block of statements, which may also contain FOR-NEXT loops. T_U_s_e_ As a statement to establish the initial, terminating, and &_incremental values of a control variable, which is used to determine the number of times a block of statements contained in a FOR-NEXT loop is to be executed. The loop is repeated until the value of the control variable meets the termination condition. T_R_e_m_a_r_k_s_ 1. R_u_l_e_s_ a. The control variable control var' must not be subscripted. &_ \f b. For every FOR or NEXT statement there must be a matching NEXT or FOR statement, otherwise an error message (0021: FOR WITHOUT NEXT or 0022: NEXT WITHOUT FOR) will be output. c. The expressions expr1', expr2', and expr3' may have positive or negative values; expr3' must not be zero. d. If the STEP expr3' argument is omitted in the FOR statement, expr3' is assumed to be +1. e. The termination condition for a FOR-NEXT loop depends on the values of expr1' and expr3'. The loop will terminate if expr3' is positive and the next value of control var' is greater than expr2', or if expr3' is negative and the next value of control var' is less than expr2'. N_o_t_e_:_ If the value of expr1' (the initial value) meets the termination condition, statements' will not be executed even once. f. If the body of a FOR-NEXT loop is entered at any point other than the FOR statement, the error message 0022: NEXT WITHOUT FOR will be output when the NEXT statement corresponding to the skipped FOR statement is encountered. g. When the termination condition is met, the loop is exited. T_2. P_r_o_g_r_a_m_ _l_o_o_p_ _o_p_e_r_a_t_i_o_n_ a. expr1', expr2', and expr3' are evaluated. If expr3' is not specified, it is assumed to be +1. &_ b. control var' is set equal to expr1'. c. If expr3' is positive (negative) and control var' is greater than (less than) expr2', the termination condition is satisfied and control passes to the first statement following the corresponding NEXTstatement; otherwise step e is performed. d. If expr3' is positive (negative) and control var' +\f expr3' is greater than (less than) expr2', the termination condition is satisfied and control passes to the first statement following the corresponding NEXT statement; otherwise control var' is set equal to control var' + expr3'. e.statements' is executed. f. Step d is repeated. T_3. N_e_s_t_e_d_ _l_o_o_p_s_ FOR-NEXT loops may be nested to a depth of seven. The FOR &_ statement and its terminating NEXT statement must be completely contained within the loop in which they are nested, for example: T_ L_e_g_a_l_ _n_e_s_t_i_n_g_ I_l_l_e_g_a_l_ _n_e_s_t_i_n_g_ FOR X = ... FOR X = ... FOR Y = ... FOR Y = ... FOR Z = ... NEXT X NEXT Z NEXT y NEXT Y &_ NEXT X T_ E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 FOR I=1 TO 25 0020 FOR J=1 TO 25 STEP 7 0030 NEXT J 0040 NEXT I 0050 PRINT I,J 0060 STOP 25 22 Final values of I and J before their terminating &_values were exceeded.\f T_E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ 0010 LET A=10 Shows nested FOR-NEXT loops. 0020 FOR I=A TO 1 STEP -1 0030 PRINT TAB(I); 0040 FOR J=A TO I STEP -1 0050 PRINT "**"; 0060 NEXT J 0070 PRINT 0080 REM NEW LINE 0090 NEXT I 0100 STOP 01234567890123456789 ** **** ****** ******** ********** ************ ************** **************** ****************** &_******************** T_ E_x_a_m_p_l_e_ _3_ 0010 DIM TEXT<(30) 0020 LET TEXT<="TEXT1TEXT2TEXT3TEXT4TEXT5TEXT6" 0030 FOR I=5 TO 0 STEP -1 0040 PRINT TEXT<(I*5+1,(I+1)*5) 0050 NEXT I 0060 STOP TEXT6 C_o_m_m_e_n_t_ _(_3_)_ TEXT5 TEXT4 A string array can be imple- TEXT3 mented by means of a FOR-NEXT TEXT2construction. &_TEXT1 \f T_ 3.13G_O_S_U_B_ _a_n_d_ _R_E_T_U_R_N_ F_o_r_m_a_t_ GOSUB line no.' . . . statements' RETURN comment' line no.': the first statement of a subroutine. statements': a block of statements. &_ comment': a text comment. T_U_s_e_ As a statement to direct program control to the first statement &_of a subroutine. RETURN exits the subroutine and returns control to the first statement following the GOSUB statement that caused the subroutine to be entered. T_ R_e_m_a_r_k_s_ 1. A subroutine is a convenient means of executing the same &_ block of statements at different places in a program. Sub- routines may be nested to a depth of seven. Nesting occurs when a subroutine is called during the execution of another subroutine. 2. A subroutine may be entered only by means of a GOSUB state- ment, otherwise the error message 0019: RETURN WITHOUT GOSUB will be output when the RETURN statement is encountered. 3. A subroutine may contain more than one RETURN statement, should program logic require the subroutine to terminate at one of a number of different places. 4. Although a subroutine may appear anywhere in a program, it is good practice to place the subroutine distinctly separate from the main program. In order to prevent inadvertent entry of the subroutine by other than a GOSUB statement, the sub- routine should be preceded by a STOP statement (see Sect. 3.36) or a GOTO statement (see Sect. 3.14) that directs control to a line number following the subroutine.\f 5. The word RETURN may be followed by a comment. T_ E_x_a_m_p_l_e_ _1_ 0010 LET I=144 0020 GOSUB 0060 0030 LET I=169 0040 GOSUB 0060 0050 STOP 0060 PRINT "THE SQUARE ROOT OF";I;"IS:";SQR(I) 0070 RETURN THE SQUARE ROOT OF 144 IS: 12 &_THE SQUARE ROOT OF 169 IS: 13 T_E_x_a_m_p_l_e_ _2_ 0010 GOSUB 0040 0020 PRINT "EXAMPLE" 0030 GOTO 0140 0040 PRINT "NEST"; 0050 GOSUB 0080 0060 PRINT "INE "; 0070 RETURN 0080 PRINT "ED "; 0090 GOSUB 0120 0100 PRINT "ROUT"; 0110 RETURN 0120 PRINT "SUB"; 0130 RETURN 0140 STOP &_NESTED SUBROUTINE EXAMPLE T_ 3.14G_O_T_O_ F_o_r_m_a_t_ GOTO line no.' line no.': a line number. &_ \f U_s_e_ As a statement to transfer control unconditionally to a statement that is not in normal sequential order. R_e_m_a_r_k_s_ 1. If control is transferred to an executable statement, that statement and those following it will be executed. 2. If control is transferred to a non-executable statement, such as DATA, program execution will continue at the first execut- able statement following the non-executable statement. T_E_x_a_m_p_l_e_ 0010 READ NUMBER 0020 PRINT NUMBER; 0030 IF NUMBER'0 THEN GOTO 0010 0040 STOP 0050 DATA 10,9,8,7,6,5,4,3,2,1,0 &_ 10 9 8 7 6 5 4 3 2 1 0 T_3.15I_F_-_T_H_E_N_ F_o_r_m_a_t_ IF expr' THEN statement' expr': an expression which, when evaluated, has &_ the value true (' 0) or false (= 0). statement': any RC BASIC statement except CASE-WHEN- ENDCASE, DATA, DEF, END, FOR-NEXT, ENDIF, ELSE, PROC-ENDPROC, REM, REPEAT-UNTIL, and WHILE-ENDWHILE. T_U_s_e_ As a statement or command to execute a single statement de- &_pending on whether the value of an expression is true or false. \f T_R_e_m_a_r_k_s_ P_r_o_g_r_a_m_ _o_p_e_r_a_t_i_o_n_ &_1. If the value of expr' is true (' 0), statement' is exe- cuted. If statement' does not cause transfer of control to another part of the program, execution will then continue at the first statement following the IF-THEN statement. 2. If the value of expr' is false (= 0), statement' is not executed. N_o_t_e_:_ Since the internal representation of non-integer numbers may not be exact (.2 cannot be represented exactly, for example), it is advisable to test for a range of values when testing for a non-integer. If, for example, the result of a computation, A, was to be 1.0, a reliable test for 1 would be IF ABS(A-1.0)_1.0E-6 THEN ... If this test succeeded, A would be equal to 1 to within 1 part in 10 6. This is approximately the accuracy of single- precision floating-point calculations. T_E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 LET I=10 The statement GOTO 40 0020 IF I'5 THEN GOTO 0040 is executed only if I ' 5. 0030 PRINT "DON"_T ENTER HERE" 0040 PRINT "PRINT THIS" 0050 STOP &_PRINT THIS T_E_x_a_m_p_l_e_ _2_a_ 0010 LET A=5; B=5 0020 PRINT "A AND B ARE"; 0030 IF A'B THEN PRINT " NOT"; 0040 PRINT " EQUAL" 0050 STOP A AND B ARE EQUAL \f T_E_x_a_m_p_l_e_ _2_b_ 0010 LET A=5; B=7 0020 PRINT "A AND B ARE"; 0030 IF A'B THEN PRINT " NOT"; 0040 PRINT " EQUAL" 0050 STOP &_A AND B ARE NOT EQUAL T_ 3.16I_F_-_T_H_E_N_-_E_N_D_I_F_ F_o_r_m_a_t_ IF expr' THEN DO statements' &_ENDIF comment' expr': an expression which, when evaluated, has the value true (' 0) or false (= 0). statements': a block of statements. comment': a text comment. T_U_s_e_ As a statement to execute a block of statements depending on whether the value of an expression is true or false. &_ T_R_e_m_a_r_k_s_ 1. R_u_l_e_s_ a. For every IF-THEN/ENDIF statement there must be a matching ENDIF/IF-THEN statement. &_ b. If statements' is entered at any point other than the IF-THEN statement, the error message 0056: ENDIF WITHOUT IF will be output when the ENDIF statement is encountered. 2. P_r_o_g_r_a_m_ _o_p_e_r_a_t_i_o_n_ a. If the value of expr' is true (' 0), statements' is executed once. b. Execution will then continue at the first statement following the ENDIF statement. \f 3. N_e_s_t_e_d_ _c_o_n_s_t_r_u_c_t_i_o_n_s_ IF-THEN-ENDIF/IF-THEN-ELSE-ENDIF constructions may be nested to a depth of seven. 4. The word ENDIF may be followed by a comment. T_E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 LET I=1 The block of statements 0020 IF I THEN betweenIF-THEN and ENDIF is 0030 PRINT "I'0" executed only if I is true 0040 LET I=I+1 (I ' 0). 0050 ENDIF 0060 PRINT "AFTER ENDIF, I=";I 0070 STOP I'0 &_AFTER ENDIF, I= 2 T_E_x_a_m_p_l_e_ _2_ 0010 LET I=0 0020 IF I THEN 0030 PRINT "DON!T ENTER HERE" 0040 LET I=I+1 0050 ENDIF 0060 PRINT "AFTER ENDIF, I=";I 0070 STOP &_ AFTER ENDIF, I= 0 T_E_x_a_m_p_l_e_ _3_ 0010 LET I=26 0020 IF I/2'=13 THEN 0030 PRINT "SHOULD ENTER HERE" 0040 ENDIF 0050 STOP &_SHOULD ENTER HERE \f T_ E_x_a_m_p_l_e_ _4_ 0010 DIM NAME<(4) 0020 LET NAME<="JOHN" 0030 IF NAME<(2,3)="OH" THEN 0040 PRINT "NAMES CONTAINS "OH" " 0050 LET NAME<(2,3)=" " 0060 PRINT NAME< 0070 ENDIF 0080 STOP NAMES CONTAINS "OH" &_J N 3.17I_F_-_T_H_E_N_-_E_L_S_E_-_E_N_D_I_F_ T_F_o_r_m_a_t_ IF expr' THEN DO statements-1' ELSE comment' statements-2' &_ENDIF comment' T_ expr': an expression which, when evaluated, has the value true (' 0) or false (= 0). statements-1': a block of statements which is executed if the value of expr' is true (' 0). statements-2': a block of statements which is executed if the value of expr' is false (= 0). comment': a text comment. U_s_e_ &_As a statement to execute one of two blocks of statements depending on whether the value of an expression is true or false. T_R_e_m_a_r_k_s_ 1. R_u_l_e_s_ If statements-1' or statements-2' is entered at any point &_other than the IF-THEN/ELSE statement, an error message\f (0051: ELSE WITHOUT IF or 0056: ENDIF WITHOUT IF) will be output when the ELSE/ENDIF statement if encountered. T_2. P_r_o_g_r_a_m_ _o_p_e_r_a_t_i_o_n_ a. expr' is evaluated. b. If the value of expr' is true (' 0), statements-1' is &_executed. c. If the value of expr' is false (= 0), statements-2' is executed. d. When statements-1' or statements-2' has been executed and if neither has caused transfer of control to another part of the program, execution will continue at the first statement following the ENDIF statement. T_3. N_e_s_t_e_d_ _c_o_n_s_t_r_u_c_t_i_o_n_s_ IF-THEN-ENDIF/IF-THEN-ELSE-ENDIF constructions may be nested &_to a depth of seven. 4. The words ELSE and ENDIF may be followed by comments. \f T_E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ 0010 DIM PRICE(4),NUMBER(4) If ITEMNO = 1 or 3, the 0020 FOR ITEMNO=1 TO 4 statements in lines 40 0030 IF (ITEMNO=1) OR (ITEMNO=3) THENand 50 are executed; 0040 LET PRICE(ITEMNO)=10otherwise the statements 0050 LET NUMBER(ITEMNO)=7 in lines 70 and 80 are 0060 ELSEexecuted. 0070 LET PRICE(ITEMNO)=25 0080 LET NUMBER(ITEMNO)=9 0090 ENDIF 0100 NEXT ITEMNO 0110 PRINT "ITEMNO","NUMBER","PRICE" 0120 FOR I=1 TO 4 0130 PRINT I,NUMBER(I),PRICE(I) 0140 NEXT I 0150 STOP ITEMNO NUMBER PRICE 1 7 10 2 9 25 3 7 10 &_ 4 9 25 T_3.18I_N_P_U_T_ F_o_r_m_a_t_ var' ,var' INPUT slit-0', svar' ,slit-n' ,svar' ... slit-0, slit-n': string literals. var': a numeric variable. &_ svar': a string variable. U_s_e_ As a statement or command to assign values entered from the user>s terminal during program execution to a list of numeric or string variables. R_e_m_a_r_k_s_ 1. When an INPUT statement is executed, the system outputs a question mark (?) as an initial prompt unless the INPUT statement contains slit-0', in which case slit-0' is output.\f 2. The user responds by typing a list of data items, each of which is separated from the next by a comma. The last item is followed by a carriage return. 3. Data items will be read as long as the arguments in the INPUT statement are var' or svar'. If a string literal, slit-n', is encountered in the argument list, slit-n' will be output and any remaining items entered by the user will be skipped. 4. If the data list is terminated (by pressing the RETURN key) before values have been assigned to all of the variables in the argument list, the system will output a question mark as a prompt, indicating that further items are expected. 5. Data entered in response to a prompt must be of the same type (numeric or string) as the variable in the argument list for which the data is being supplied. Variables in the argument list may be subscripted or unsubscripted. 6. If the entered data does not match the type of a variable in the argument list, the system will output / ? in response to the erroneous input. The user can then enter data of the correct type. 7. A comma may not be used as a separator between string data items. These items must be separated either by a carriage return or, if typed on the same line, by a quotation mark (") followed by a comma. \f T_E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_s_ _(_1_)_ * LIST 0010 DIM NAME<(20),ADDRESS<(20) 0020 INPUT NAME<,ADDRESS< 0030 PRINT NAME<,ADDRESS< 0040 INPUT "NAME ",NAME<,"ADDRESS ",ADDRESS< 0050 PRINT NAME<,ADDRESS< * RUN ? R_O_B_E_R_T_ _C_L_A_R_K_)__ ? 9_ _M_A_I_N_ _S_T_R_E_E_T_)__ ROBERT CLARK 9 MAIN STREET PRINT output. NAME R_A_Y_M_O_N_D_ _C_L_A_R_K_E_)__ ADDRESS 6_1_ _H_I_G_H_W_A_Y_)__ RAYMOND CLARKE 61 HIGHWAY PRINT output. END The underlined texts are AT 0050 those entered by the user. &_* T_ E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_s_ _(_2_)_ * LIST The underlined texts are 0010 INPUT N1,N2,N3,N4 those entered by the user. 0020 PRINT N1;N2;N3;N4 * RUN ? 1_)_ _ A question mark is output ? 2_)_ _ as a prompt until data ? 3_)_ _ has been supplied for all ? 4_)__arguments. 1 2 3 4 &_ T_END AT 0020 * RUN ? 5_,_6_,_7_,_8_)_ _ All data items can be 5 6 7 8 typed on a single line when separated by commas. END &_AT 0020\f T_* RUN ? 9_)__ ? U_)__ The type of the entered data / ? 8_)__items must match the type of ? 7_)__the arguments. ? Y_)_ _ / ? 6_)_ _ 9 8 7 6 END AT 0020 &_* T_ 3.19L_E_T_ F_o_r_m_a_t_ var'var' LET svar' = expr' ; svar' = expr' ... &_ var': a numeric variable. svar': a string variable. expr': a numeric, relational, or string expression. U_s_e_ As a statement or command to evaluate an expression and assign the resultant value to a variable. R_e_m_a_r_k_s_ 1. Use of the mnemonic LET is optional. 2. The variables may be subscripted. 3. Numeric or relational expressions may be assigned to numeric variables. 4. String expressions may be assigned to string variables. T_E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 10 LET A=A+1 The variable A is assigned a value one greater than it was &_before. \f T_E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ 20 A(2,1)=B 2+10 The element in row 2, column 1 of the array A is assigned the value of the expression &_ B 2+10. T_E_x_a_m_p_l_e_ _3_ C_o_m_m_e_n_t_ _(_3_)_ 0010 LET I=3 One line may contain several 0020 LET J=4 assignments as shown in line 0030 LET K=I+J; L=I*J 30. 0040 PRINT I,J,K,L 0050 STOP &_3 4 7 12 T_ 3.20 LOWBOUND F_o_r_m_a_t_ LOWBOUND=expr' expr': a numeric expression which evaluates to an integer &_ U_s_e_ As a command or statement to change the lower bound of numeric and string arrays. R_e_m_a_r_k_ 1. The default lower bound is 1 (i.e. the number of the first element in an array is one). By means of the LOWBOUND-statement the lower bound may however be changed. 2. All rows and columns are included in all matrix-operations. 3. The LOWBOUND-statement can be placed anywhere in an RC BASIC program. Each time an array element is referenced the current lower bound will be taken as the first element of the array.\f T_ E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ 0010 LOWBOUND =1 0020 DIM A(5) 0030 FOR I=1 TO 5 0040 LET A(I)=I 0050 NEXT I 0060 FOR I=1 TO 5 lower bound of A-array is 1 0070 PRINT A(I); 0080 NEXT I 0090 LOWBOUND =0 0100 DIM B(5) 0110 PRINT 0120 FOR I=0 TO 4 now lower bound of A-array is 0 0130 PRINT A(I); 0140 NEXT I 0150 PRINT 0160 FOR I=0 TO 5 B-array has 6 elements (0 to 5) 0170 PRINT B(I); 0180 NEXT I 1 2 3 4 5 1 2 3 4 5 &_0 0 0 0 0 0 T_3.21N_E_W_ For description, see Chapter 9. &_ T_3.22O_N_-_E_R_R_ F_o_r_m_a_t_ ON ERR THEN statement' statement': any RC BASIC statement except CASE-WHEN- ENDCASE, DATA, DEF, END, FOR-NEXT, ENDIF, ELSE, ON, PROC-ENDPROC, REM, REPEAT-UNTIL, and WHILE-ENDWHILE. &_ U_s_e_ As a statement to enable the programmer to take special action, if an error occurs during program execution. \f R_e_m_a_r_k_s_ 1. Usually a program is interrupted and an error message output, if an error occurs during program execution. If an ON-ERR statement has been executed, however, a run-time error will cause statement' to be executed. 2. The ON-ERR statement closely resembles the ON-ESC statement; see, therefore, Section 3.23, Remarks 2 to 5, for further details. T_E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ 0010 ON ERR THEN EXEC OUTERROR If an error occurs, the 0020 LET A=10/0 error codewill be output 0030 LET B=D and execution will continue. 0040 LET C=SYS(18) 0050 PROC OUTERROR 0060 PRINT "ERROR :";SYS(7) 0070 ON ERR THEN EXEC OUTERROR 0080 ENDPROC ERROR : 16 0016: ARITHMETIC ERROR ERROR : 17 0017: UNDEFINED VARIABLE ERROR : 34 0034: ILLEGAL FUNCTION ARGUMENT &_ T_3.23O_N_-_E_S_C_ F_o_r_m_a_t_ ON ESC THEN statement' statement' : any RC BASIC statement except CASE-WHEN- ENDCASE, DATA, DEF, END, FOR-NEXT, ENDIF, ELSE, ON, PROC-ENDPROC, REM, REPEAT-UNTIL, and WHILE-ENDWHILE. &_ U_s_e_ As a statement to enable the programmer to take special action, if the ESCape key is pressed during program execution. \f R_e_m_a_r_k_s_ 1. Usually a program is interrupted, if the ESCape key is pres- sed during program execution. If an ON-ESC statement has been executed, however, pressing the ESCape key will cause state- ment' to be executed. 2. If the ESCape key has been pressed once and statement' has been executed, the program will be interrupted if the ESCape key is pressed again, unless a new ON-ESC statement has been executed (see Example). 3. If statement' is a GOSUB or EXEC statement, then when a RETURN or ENDPROC statement is encountered, control will be transferred to the statement following the last statement executed before the ESCape key was pressed. 4. ON-ESC statements may be placed anywhere in a program, so that different actions may be taken in different parts of the program. 5. Execution of the statement ON ESC THEN STOP will in all circumstances cause restoration of the normal ESCape key function. \f T_E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ * LIST 0010 ON ESC THEN GOSUB 0060 0020 FOR I=1 TO 20 0030 PRINT I; 0040 NEXT I 0050 STOP 0060 PRINT 0070 PRINT "ESCAPE PRESSED, I = ";I 0080 RETURN * RUN 1 2 3 4 5 ESCAPE PRESSED, I = 6 7 8 9 10 11 1 When ESC is pressed a STOP second time, the program AT 0030is interrupted. * LIST 0010 ON ESC THEN GOSUB 0060 0020 FOR I=1 TO 20 0030 PRINT I; 0040 NEXT I 0050 STOP 0060 PRINT 0070 PRINT "ESCAPE PRESSED, I = ";I 0075 ON ESC THEN GOSUB 0060 This statement has been 0080 RETURN inserted in the program above. * RUN 1 2 3 4 5 ESCAPE PRESSED, I = 5 6 7 8 9 1 ESCAPE PRESSED, I = 10 11 12 13 14 15 16 ESCAPE PRESSED, I = 16 17 18 19 20 STOP AT 0050 &_*\f T_ 3.24O_N_-_G_O_T_O_/_G_O_S_U_B_ F_o_r_m_a_t_ GOTO ON expr' THEN GOSUB line no.' ,line no.' ... expr': a numeric expression which is evaluated to an integer. line no.': a line number in the current program. The positions of line numbers in the argument list are numbered in sequence from 1 to n. U_s_e_ As a statement to transfer control to one of several lines in a program depending on the computed value of an expression when &_the ON statement is executed. R_e_m_a_r_k_s_ 1. expr' is evaluated. If it is not an integer, the fractional part is ignored. 2. The program transfers control to the line whose s_e_q_u_e_n_c_e_ n_u_m_b_e_r_ _i_n_ _t_h_e_ _a_r_g_u_m_e_n_t_ _l_i_s_t_ corresponds to the computed value of expr'. 3. If expr' evaluates to an integer that is greater than the sequence number of the last line number in the argument list or that is less than or equal to zero, the ON statement is ignored and control passes to the next statement. 4. The ON-GOSUB statement must contain a list of line numbers each of which is the first line of a subroutine within the current program. \f T_E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ 10 ON M-5 GOTO 500,75,1000 If M-5 evaluates to 1, 2, or 3, control will be trans- ferred to line number 500, 75, or 1000, respectively. If M-5evaluates to any other value, control will be transferred to the next sequential statement in the program. &_ T_ 3.25P_A_G_E_ F_o_r_m_a_t_ PAGE=expr' expr': a numeric expression in the range 0 = expr' = 132. &_ U_s_e_ As a command or statement to set the right-hand margin of the terminal. R_e_m_a_r_k_s_ 1. The default page width (length of a print line) is 72 columns. 2. If the page width is set to zero, the system will regard the length of the print line as infinite and consequently not out- put an automatic carriage return and line feed in PRINTstate- ments (see Ch. 3). The user may find this advantageous when using the X-Y addressing facilities of a video terminal. \f T_E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ * LIST 0010 FOR I=1 TO 10 0020 PRINT I; 0030 NEXT I * PAGE=30 * RUN 1 2 3 4 5 6 7 8 9 The system outputs a carriage 10 return and line feed when the END page width (length of the AT 0030 print line) is exceeded. * PAGE=20 * RUN 1 2 3 4 5 6 7 8 9 10 END AT 0030 &_* T_ 3.26P_R_I_N_T_ F_o_r_m_a_t_ expr' expr' ;slit' , slit' , PRINT svar' ; svar' ... ; expr': a numeric or relational expression. slit': a string literal. svar': a string variable. &_ U_s_e_ As a statement or command to perform any of the following output operations at the user>s terminal: 1. Print variables and constants (numeric or string). 2. Print the result of a computation. \f 3. Print a combination of 1 and 2. 4. Print a blank line (skip a line). R_e_m_a_r_k_s_ 1. P_r_i_n_t_i_n_g_ _n_u_m_b_e_r_s_ Numbers (integer, decimal, or E-type) are printed in the following form: sign'number'space' The sign is either minus (-) or a blank space for plus; the number is always followed by a blank space (see Ch. 2). 2. Z_o_n_e_ _s_p_a_c_i_n_g_ _o_f_ _o_u_t_p_u_t_ The print line on a terminal is divided into print zones. The width of a print zone can be set by means of the TAB command (see Ch. 3.37). The default zone spacing is 14 columns. This T_ spacing is used in the examples below. The first column on a print line is column number 0. 0 13 14 27 28 41 42 55 56 69 14 14 14 14 14 columns columns columns columns columns &_ A c_o_m_m_a_ (,) between items in the argument list causes the next print element to be output starting from the leftmost position of the next zone. If there are no more zones on the current line, printing continues in the first zone on the next line. If a print element requires more than one zone, the next element is printed in the next free zone (see Ex. 1 and 3). Before each print element is output, its length is compared with the space remaining on the current line. If the space is insufficient, the element is moved to the next line. If the length of an element is greater than the length of the print line (see the PAGE command, Ch. 3.25), the error message 0133: PRINT ELEMENT TOO LONG is output. \f T_3. C_o_m_p_a_c_t_ _s_p_a_c_i_n_g_ _o_f_ _o_u_t_p_u_t_ A s_e_m_i_c_o_l_o_n_ (;) between items in the argument list causes the next print element to be output starting from the next character position. &_ N_o_t_e_:_ A blank space is always printed after a number. A blank space is also reserved for the plus (+) sign, even though the sign is not printed (see Ex. 2). 4. S_p_a_c_i_n_g_ _t_o_ _t_h_e_ _n_e_x_t_ _l_i_n_e_ When the last element in a PRINT statement argument list has been printed, a carriage return and line feed are output u_n_l_e_s_s_ this last element is followed by a comma or a semi- colon, in which case the carriage return and line feed are suppressed and the elements in the next PRINT statement argument list are printed on the same line in accordance with the comma or semicolon punctuation (see Ex. 2 and 3). 5. P_r_i_n_t_i_n_g_ _b_l_a_n_k_ _l_i_n_e_s_ A PRINT statement with no arguments or punctuation causes a carriage return and line feed to be output (see Ex. 4). 6. A_d_d_i_t_i_o_n_a_l_ _p_r_i_n_t_i_n_g_ _v_e_r_s_a_t_i_l_i_t_y_ See the TAB(X) function (Sect. 3.38), the PAGE and TAB commands (Ch. 3.25 and 3.37), and the PRINT USING statement (Sect. 3.27). T_E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 LET X=25 If a print element 0020 PRINT "THE SQUARE ROOT OF X IS:",SQR(X)requires more than 0030 STOP one zone, the next element is printed in the next free 012345678901234567890123456789012345678901zone. &_THE SQUARE ROOT OF X IS: 5 \f T_ E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ 0010 LET X=5 Shows the use of 0020 PRINT X;X X;X*X;X 2; the semicolon as 0030 PRINT SQR(X);SQR(X) 2 a spacing charac- 0040 PRINT -X;(-X) 3 ter. The semicolon 0050 STOPterminating line 20 suppresses a carriage return 012345678901234567890123456789012345678901and line feed. 5 3125 25 25 2.23607 5 &_-5 -125 T_ E_x_a_m_p_l_e_ _3_ C_o_m_m_e_n_t_ _(_3_)_ 0010 LET X=100 Shows the use of 0020 PRINT X,X 2,SQR(X), the comma as a 0030 PRINT X 3 spacing character. 0040 PRINT "END" The comma termina- 0050 STOPting line 20 sup- presses a carriage return and line feed. 01234567890123456789012345678901234567890123456789012345 100 10000 10 1E+6 &_END T_ E_x_a_m_p_l_e_ _4_ C_o_m_m_e_n_t_ _(_4_)_ 0010 LET X=10 The PRINT statement 0020 PRINT X, in line 40 causes a 0030 PRINT X 2, carriage return 0040 PRINTand line feed to 0050 PRINT X,be output. 0060 PRINT X 2 0070 PRINT"END" 0080 STOP 0123456789012345678901234567 10 100 10 100 &_END\f T_ E_x_a_m_p_l_e_ _5_ C_o_m_m_e_n_t_ _(_5_)_ 0010 DIM A<(10) If a print ele- 0020 LET A<="ABCDE" ment is a rela- 0030 PRINT A<="ABCDE";A<"ABCDEF";A<'"B";1=1;2'5tional expres- 0040 STOPsion, either the word TRUE TRUE TRUE FALSE TRUE FALSE or the word FALSE will be &_printed. T_ 3.27P_R_I_N_T_ _U_S_I_N_G_ F_o_r_m_a_t_ expr' expr' PRINT USING format', slit' , slit' ... , svar' ; svar' ; &_ T_ format': a string literal or string variable that specifies the format (see Remarks) for printing the items in the argument list. expr': a numeric or relational expression. slit': a string literal. &_ svar': a string variable. U_s_e_ As a statement to output the values of items in the argument list using a specified format. R_e_m_a_r_k_s_ 1. The occurrence of a separator other than a comma, e.g. a semicolon or TAB, between items in the argument list will cause the remaining items to be printed as if no format had been specified (see the PRINT statement, Sect. 3.26). 2. The PRINT USING statement is executed as a PRINT statement (see Sect. 3.26); however, if the system does not include the PRINT USING facility, execution of a PRINT USING statement will cause the string format' to be printed, followed by the items in the argument list. \f 3. The format' expression may have more than one format' T_ field and may include string literals as well as the following special characters, which are used to format numeric output: &_ # . + - < , T_ N_o_t_e_:_ The character is used in the following descriptions to indicate a blank space. a. D_i_g_i_t_a_l_ _r_e_p_r_e_s_e_n_t_a_t_i_o_n_ _(_#_)_ For each # in the format' field, a digit (0-9) is substi- tuted from the expr' argument. _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ #####2525 The digits are right justified in the field with leading blanks. ##### -30 30 Signs and othernon- digits are ignored. ##### 1.95 2 Only integers are represented; the number is rounded to an integer. ##### 598745 ***** If the number in expr' has more digits than speci- fied by format', a field of all as- &_ terisks is output. T_ b. D_e_c_i_m_a_l_ _p_o_i_n_t_ _(_._)_ The decimal character (.) places a decimal point within the &_ string of digits in the fixed position in which it appears in format'. Digit (#) positions which follow the decimal point are filled; no blank spaces are left in these digit posi- tions. When expr' contains more fractional digits than format' allows, the fraction will be rounded to the limit of format'. When expr' contains less fractional digits than specified by format' , zeroes are output to fill the positions.\f T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ #####.## 20 20.00 Fractional posi- tions are filled with zeroes. #####.## 29.347 29.35 Rounding occurson fractions. #####.## 789012.34 ******** When expr' has too many signi- ficant digits to the left of a de- cimal point, a field of all aste- risks, including the decimal point, &_ is output. T_ c. F_i_x_e_d_ _s_i_g_n_ _(_+_ _o_r_ _-_)_ &_ A fixed sign character appears as a single plus (+) or minus (-) sign either in the first character position or in the last character position in the format' field. A fixed plus (+) sign prints the sign (+ or -) of expr' in the position in which the fixed plus (+) sign is placed in format'. A fixed minus (-) sign prints a minus (-) sign for negative values of expr' or a blank space for positive values of expr' in the position in which the fixed minus (-) sign is placed in format'. When a fixed sign is used, any leading zeroes appearing in expr' will be replaced by blanks, except for a single leading zero preceding a decimal point.\f T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ +##.## 20.5 +20.50 +##.## 1.01 +1.01 Blanks precede the number. +##.## -1.236 -1.24 +##.## -234.0 ****** ###.##- 20.5 20.50 ###.##- 000.01 0.01 One leading zero before the decimal point is printed. ###.##- -1.236 1.24- &_ ###.##- -234.0 234.00- T_ d. F_l_o_a_t_i_n_g_ _s_i_g_n_ _(_+_+_ _o_r_ _-_-_)_ A floating sign appears as two or more plus (++) or minus &_ (--) signs at the beginning of the format' field. A floating plus (++) sign outputs a plus or minus sign immediately before the value of expr' with no separating blank spaces as would occur with a fixed sign. A floating minus (--) sign outputs either a minus or a blank (for plus) immediately preceding the value. Positions occupied in format' by the second sign and any additional signs can be used for numeric positions in the value of expr'. \f T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ ---.## -20 -20.00 The second and third minus signs are treated as # on output. ---.## -200 ******Too many digits to the left of the decimal point. ---.## 2 2.00 Note that format' may include a floating sign (++ or --) or a floating dollar sign (<<), as described below, but not both. e.F_i_x_e_d_ _d_o_l_l_a_r_ _s_i_g_n_ _(_<_)_ A fixed dollar sign appears as a single dollar (<) sign in either the first or the second character position in the format' field, causing a dollar (<) sign to be output in that position. If the dollar sign (<) is in the second position, it must be preceded by a fixed sign (+ or -). A fixed dollar sign (<) causes leading zeroes in the value &_ of expr' to be replaced by blanks. T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ -<###.## 30.512 <30.51 <###.##+ -30.512 <30.51- &_ f. F_l_o_a_t_i_n_g_ _d_o_l_l_a_r_ _s_i_g_n_ _(_<_<_)_ A floating dollar sign appears as two or more dollar (<<) signs beginning in either the first or the second character position in the format' field. If the dollar signs (<<) start in the second position, they must be preceded by a fixed sign (+ or -). A floating dollar sign (<<) causes a dollar (<) sign to be placed immediately before the first digit of the expr' value. Note that format' may include a floating dollar sign (<<) or a floating sign (++ or --), as described above, but not both.\f T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ +<<<#.## 13.20 +<13.20 Additional dollar signs may be replaced by #,as with floating signs (++ and --). &_ <<##.##- -1.0 <01.00- Leading zeroes are not sup- pressed in the # part of the field. g. S_e_p_a_r_a_t_o_r_ _(_,_)_ The comma separator (,) places a comma in the fixed position in which it appears in a string of digits in the format' field. If a comma would be output in a field of suppressed leading zeroes (blanks), a blank space is output in the position for the comma. T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ +<#,###.## 30.6 +<30.60 A blank space is output for the comma. +<#,###.## 2000 +<2,000.00 ++##,### 00033 +00,033 A comma is printed when leading zeroes are not suppressed. &_ T_ h. E_x_p_o_n_e_n_t_ _i_n_d_i_c_a_t_o_r_ _(_ _ _ _ _)_ Four consecutive up-arrows ( ) are used to indicate an &_ exponent field in format'. The four arrows will be output as E+nn, where each n is a digit. \f If the exponent field in format' does not contain exactly four up-arrows, a run-time error will result. T_ _f_o_r_m_a_t_'_ _e_x_p_r_'_ O_u_t_p_u_t_ C_o_m_m_e_n_t_s_ +##.## 170.35 +17.03E+01 +##.## -.2 -20.00E-02 ++##.## 6002.35 +600.24E+01 &_ 4. A format' expression, as previously remarked, may have more than one format' field and may include string literals as well as the special formatting characters just described. Values of items in the argument list of the PRINT USING statement are sequentially assigned to format' fields. T_ RC BASIC distinguishes string literals from format' fields by the characters that appear in the latter, for example: "TWO FOR <1.25" <1.25 is part of the string literal. "TWO FOR <<<.##" <<<.## is a format' field in theformat' expression. "ANSWER IS -85" -85 are characters of a string literal. "ANSWER IS -###" -### is a format' field in &_ the format' expression. T_5. A format' expression may be specified by referencing a previously defined string variable, for example: 15 DIM S<(10) 20 LET S<="##.##" 30 PRINT USING S<,1.5,2 &_ 6. format' fields in a format' expression are delimited by the use of a non-formatting character before or after the format'\f T_ field, for example: f_i_e_l_d_ _d_e_l_i_m_i_t_e_r_ f_i_e_l_d_ _d_e_l_i_m_i_t_e_r_ "#####FOR<<###.##" format field format field string literal &_ 7. String literals may appear in the argument list of the PRINT USING statement and will be superimposed on a format' field in the following manner: a. Each character of the string literal replaces a single format' field character, which may be any of the special formatting characters, i.e. #, decimal point, +, -, <, comma, and . b. Strings are left justified in the format' field, and filled with spaces, if necessary. c. If the number of characters in the string is greater than the number of characters in the format' field, the string will be truncated to fit the field, for example: 5 PRINT USING "###,###.##","TEST","CHARACTER","SEVENTY-FIVE" RUN TESTCHARACTERSEVENTY-FI T_8. When there are more items in the argument list than format' fields in the format' expression, the format' fields will be used repetitively. Thus, for example, in "####Æ<###.##PER###" the first, fourth, seventh, etc. items will be formatted using the format' field ####; the second, fifth, eighth, etc. items &_ using the format' field <###.##; and the third, sixth, ninth, etc. items using the format' field ###. The embedded blank spaces, Æ sign, and PER are string literals and delimitthe format' fields. \f T_E_x_a_m_p_l_e_s_ C_o_m_m_e_n_t_s_ . . . 100 PRINT USING "A(#)=##.#",I,A(I) . . . RUN A(1)=17.9 Possible output includes two format' fields and two string literals. . . . 100 PRINT USING "###.##",I,A,B . . . RUN 1.0017.9025.77 Possible output with the format' expression repeated for each item in the argument list. &_ T_3.28 PRINTDATE F_o_r_m_a_t_ PRINTDATE expr1', expr2', expr3' expr1' expr2' a numeric expression expr3' &_ U_S_E_ As a statement or command to print a variable with a date layout the value of expr1' is considered a date in the format yymmdd. The value of expr2' is considered a time in the format hhmmss. The value of expr3' is used as the format, determining the type of output. The value is considered as a bit pattern. \f T_ Value of bit Print result 1 hours and minutes 2 seconds 4 19 in front of year 8 d. in front of date (and no points between yy, mm and dd) 16 date is printed as ddmmyy 32 output is followed by extra space 64 space in front of output &_ T_ E_x_a_m_p_l_e_ _1_ 0010 PRINTDATE SYS(17), SYS(18), 2+4 0020 PRINTDATE SYS(17), SYS(18), 1+8 0030 STOP 1978.09.26 10.31.05 d.780926.1031 &_ T_ E_x_a_m_p_l_e_ _2_ 0010 PRINTDATE VAR, 0, 4+16 0020 STOP 25.07.1978 &_ T_ 3.29 PRINTEPS F_o_r_m_a_t_ PRINTEPS = expr' expr': a numeric expression in the range E-100 to 1. &_ U_S_E_ As a statement or command to specify the smallest number which will not be printed as zero by a PRINT statement. R_e_m_a_r_k_s_ The default value is 1E-10; E_x_a_m_p_l_e_ PRINTEPS = E-8\f T_ 3.30P_R_O_C_-_E_N_D_P_R_O_C_ F_o_r_m_a_t_ PROC name' statements' ENDPROC comment' name': the name of a procedure. name' may also be a simple numeric variable. statements':a block of statements. comment': a text comment. &_ U_s_e_ As a statement to define a procedure which can be called by means of an EXEC statement (see Sect. 3.11). T_R_e_m_a_r_k_s_ 1. A procedure is a convenient means of executing the same block of statements at different places in a program. Procedures may be nested to a depth of seven. Nesting occurs &_ when a procedure is called during the execution of another procedure. 2. R_u_l_e_s_ a. For every PROC/ENDPROC statement there must be one and only one ENDPROC/PROC statement. b. A procedure may be placed anywhere in the program. When a PROC statement is encountered, a search is made for the corresponding ENDPROC statement, and program execution continues from the first statement following this ENDPROC statement. c. If the body of a procedure is entered without use of an EXEC statement, the error message 0019: RETURN WITHOUT GOSUB will be output when the ENDPROC statement is encountered. d. A procedure may contain one or more RETURN statements. When encountered, RETURN has the effect of an ENDPROC statement. \f e. If the name of the procedure, name', is a simple numeric variable, it may be assigned a value before the procedure is called; it may also be assigned a new value by the procedure before control is returned to the main program. T_3. P_r_o_g_r_a_m_ _o_p_e_r_a_t_i_o_n_ a. When the procedure is called, execution starts at the first statement following the PROC statement. b. Execution continues until a RETURN or ENDPROC statement is encountered; after this, control is passed to the first statement following the EXEC statement that called the procedure. 4. The word ENDPROC may be followed by a comment. &_ T_E_x_a_m_p_l_e_ 0010 PROC GCD 0020 REM THE PROCEDURE FINDS THE GREATEST COMMON DIVISOR IN AAND B 0030 PRINT "GCD IN";A;"AND";B;":", 0040 WHILE A'B DO 0050 IF A'B THEN 0060 LET A=A-B 0070 ELSE 0075 LET B=B-A 0080 ENDIF 0090 ENDWHILE 0100 LET GCD=A 0110 REM A AND B DESTROYED 0120 ENDPROC 0130 REM 0140 REM MAIN PROGRAM, A AND B ARE READ FROM THE TERMINAL 0150 REM 0160 INPUT A,B 0170 IF (A=0) OR (B=0) THEN STOP 0180 EXEC GCD 0190 PRINT GCD 0200 GOTO 0160 &_ \f T_GCD IN 1 AND 1 : 1 GCD IN 2 AND 4 : 2 GCD IN 24 AND 68 : 4 GCD IN 24 AND 16 : 8 GCD IN 16 AND 24 : 8 GCD IN 345 AND 27 : 3 GCD IN 345 AND 344 : 1 GCD IN 6 AND 11 : 1 GCD IN 11 AND 66 : 11 GCD IN 1 AND 100 : 1 GCD IN 56 AND 7 : 7 GCD IN 56 AND 8 : 8 &_ T_3.31R_A_N_D_O_M_I_Z_E_ F_o_r_m_a_t_ &_RANDOMIZE U_s_e_ As a statement or command to cause the random number generator to start at a different point in the sequence of random numbers generated by the RND(X) function (see Ch. 4). R_e_m_a_r_k_s_ 1. Normally, the same sequence of random numbers is generated by successive use of the RND(X) function. This feature is useful in debugging programs. If, when the program has been found to run successfully, different starting points in the sequence are desired, the RANDOMIZE statement should be included in the program before the first occurrence of an RND(X) function. 2. The RANDOMIZE statement resets the random number generator based on the time of day, thereby producing different random numbers each time a program using the RND(X) function is run. \f T_ E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ * LIST This program produces 0010 LET I=0 different results each time 0015 RANDOMIZE it is executed. 0020 REPEAT 0030 PRINT RND(I); 0040 LET I=I+1 0050 UNTIL I=4 0060 STOP 0070 GOTO 0010 * RUN .921699 .341465 .710697 .816505 STOP AT 0060 * RUN .249755 .980187 .616137 .890037 STOP AT 0060 * CON .159747 .605283 .118429 .322262 STOP AT 0060 &_* T_ 3.32R_E_A_D_ F_o_r_m_a_t_ var',var' READ svar' ,svar' ... var': a numeric variable. svar': a string variable. &_ U_s_e_ As a statement or command to read in values from the list defined by one or more DATA statements and to assign the values to the variables listed in the READ statement. R_e_m_a_r_k_s_ 1. READ statements are always used in conjunction with DATA statements (see Sect. 3.4). 2. The variables listed in the READ statement may be subscripted or unsubscripted numeric or string variables.\f 3. The order in which variables appear in the READ statement is the order in which values for the variables are retrieved from the DATA statement list. 4. A data element pointer is moved to the next available value in the DATA statement list as values are retrieved for variables in the READ statement. If the number of variables in the READ statement exceeds the number of values in the DATA statement list, the error message 0137: NO MORE DATA FOR READ is output. 5. The type (numeric or string) of the READ statement variable must match the type of the corresponding data element value, otherwise the error message 0066: TYPE CONFLICT is output. 6. The RESTORE statement (see Sect. 3.35) can be used to reset the data element pointer to the first item of the lowest numbered DATA statement or the first item of a particular DATA statement. T_E_x_a_m_p_l_e_ 0010 DIM TEXT<(20),A(10) 0020 READ TEXT<,NUMBER 0030 DATA "READ DATA",25,1,2 0040 READ A(2),A(4) 0050 PRINT "TEXT","NUMBER","A(2)","A(4)" 0060 PRINT TEXT<,NUMBER,A(2),A(4) 0070 STOP TEXT NUMBER A(2) A(4) READ DATA 25 1 2 &_ T_3.33R_E_M_ F_o_r_m_a_t_ REM comment' comment': a text comment. &_ U_s_e_ As a statement to insert explanatory comments within a program. \f R_e_m_a_r_k_s_ 1. REM statements are non-executable, but are stored with the program and output exactly as entered when LISTed (see LIST, Ch. 9). 2. If control is transferred to a REM statement from a GOTO or GOSUB statement, execution continues from the next executable statement following the REM statement. If no executable state- ment follows the REM statement, the program will act as if an END statement (see Sect. 3.9) had been encountered and control will return to interactive mode. 3. Optional text comments may also be inserted after the words ENDCASE, END, RETURN, ENDIF, ELSE, ENDPROC, REPEAT, STOP, and ENDWHILE, for example: ENDWHILE END OF SEARCH T_E_x_a_m_p_l_e_ 10 REM REMARKS THROUGHOUT A PROGRAM CAN 20 REM HELP EXPLAIN THE PURPOSE OF STATEMENTS. 30 REM LINES 10, 20, and 30 ARE NOT EXECUTED. &_ T_ 3.34R_E_P_E_A_T_-_U_N_T_I_L_ F_o_r_m_a_t_ REPEAT comment' statements' UNTIL expr' comment': a text comment. statements': a block of statements. expr': a relational expression. &_ U_s_e_ As a statement to execute a block of statements repetitively until the value of an expression is true. R_e_m_a_r_k_s_ 1. R_u_l_e_s_ a. expr' is a relational expression whose value is either\f true or false, e.g. NAME< = "JOHN", I ' 25. b. If the body of a REPEAT-UNTIL loop is entered at any point other than the REPEAT statement, the error message 0058: UNTIL WITHOUT REPEAT will be output when the UNTIL state- ment corresponding to the skipped REPEAT statement is encountered. 2. P_r_o_g_r_a_m_ _l_o_o_p_ _o_p_e_r_a_t_i_o_n_ a. statements' is executed. b. expr' is evaluated. c. If the value of expr' is false, step a is repeated. d. If the value of expr' is true, the termination condition is satisfied and control passes to the first statement following the corresponding UNTIL statement. N_o_t_e_:_ statements' is always executed at least once. 3. N_e_s_t_e_d_ _l_o_o_p_s_ REPEAT-UNTIL loops may be nested to a depth of seven. 4. The word REPEAT may be followed by a comment. T_ E_x_a_m_p_l_e_ _1_ C_o_m_m_e_n_t_ _(_1_)_ 0010 LET I=1 The block of statements 0020 REPEAT between REPEAT and 0030 PRINT I; UNTIL is repeated 0040 LET I=I+1until I ' 10. 0050 UNTIL I'10 0060 PRINT "13'10'AFTER "UNTIL", I=";I 0070 STOP 1 2 3 4 5 6 7 8 9 10 &_ AFTER "UNTIL", I= 11 \f T_E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ 0010 LET I=20 The block of statements 0020 REPEAT between REPEAT and 0030 PRINT "EXECUTED ONCE" UNTIL is always execu- 0040 LET I=I-1ted at least once. 0050 UNTIL I'10 0060 PRINT "AFTER "UNTIL", I=";I 0070 STOP EXECUTED ONCE &_AFTER "UNTIL", I= 19 T_ E_x_a_m_p_l_e_ _3_ C_o_m_m_e_n_t_ _(_3_)_ 0010 LET A=10; B=1 Shows nested REPEAT-UNTIL 0020 REPEATloops. 0030 PRINT 0040 PRINT "A=";A, 0050 REPEAT 0060 PRINT "B=";B; 0070 LET B=B+1 0080 UNTIL B=5 0090 LET B=1; A=A-1 0100 UNTIL A7 0110 PRINT 0120 PRINT "AFTER LAST "UNTIL", A,B=";A;B &_ 0130 STOP T_A= 10 B= 1 B= 2 B= 3 B= 4 A= 9 B= 1 B= 2 B= 3 B= 4 A= 8 B= 1 B= 2 B= 3 B= 4 A= 7 B= 1 B= 2 B= 3 B= 4 AFTER LAST "UNTIL", A,B= 6 1 &_ T_3.35R_E_S_T_O_R_E_ F_o_r_m_a_t_ RESTORE line no.' line no.': a DATA statement line number. &_ U_s_e_ As a statement or command to reset the data element pointer\f either to the beginning of the DATA statement list or to a particular DATA statement. R_e_m_a_r_k_s_ 1. If the RESTORE statement is used without an argument, the data element pointer is reset to the beginning of the DATA statement list, i.e. to the first item in the lowest numbered DATA statement (see Sect. 3.4). 2. If the RESTORE statement contains an argument, the data element pointer is reset to the first item in the DATA statement specified by line no'. 3. If line no.' does not exist in the program, the data element pointer is reset to the beginning of the DATA statementlist. T_E_x_a_m_p_l_e_ C_o_m_m_e_n_t_ 0010 DATA 1,2,3,4 One can choose among several 0020 READ I,J,K,L DATA statements by means of 0030 RESTORE RESTORE. In line 30, the 0040 REM RESET TO BEGINNING data element pointer is 0050 READ M,N reset to the beginning of 0060 RESTORE 0100 the DATA statement list. 0070 REM RESET TO LINE 100 0080 READ O,P,Q,R 0090 PRINT I;J;K;L;M;N;O;P;Q;R 0100 DATA 5,6,7,8 0110 STOP &_ 1 2 3 4 1 2 5 6 7 8 T_ 3.36S_A_V_E_ For description, see Chapter 9. &_ \f T_ 3.37S_T_O_P_ F_o_r_m_a_t_ STOP comment' comment': a text comment. &_ U_s_e_ As a statement to terminate execution of the current program and to return control to interactive mode. R_e_m_a_r_k_s_ 1. STOP statements may be placed anywhere in the program. When STOP is encountered, the system will terminate execution and output the following on the user>s terminal: T_ STOP AT xxxx' * xxxx': the line number of the STOP statement. &_ 2. After control has returned to interactive mode, the program may be restarted from the first line number (see RUN, Ch. 9) or continued in its current state (see CON or RUN line no.', Ch. 9). 3. The word STOP may be followed by a comment. T_E_x_a_m_p_l_e_ * LIST 0010 REM TERMINATE PROGRAM BY STOP 0020 INPUT A 0030 IF A0 THEN STOP 0040 GOTO 0020 * RUN ? 1 ? 3 ? -5 STOP AT 0030 &_ * \f T_ 3.38T_A_B_ F_o_r_m_a_t_ TAB=expr' expr': a numeric expression in the range 1 = expr' = page width specified by the PAGE &_ command. U_s_e_ As a command or statement to set the zone spacing between the print elements output by PRINT statements (see Ch. 3.26). R_e_m_a_r_k_s_ 1. The default zone spacing (width of a print zone) is 14 columns. This spacing allows five print zones per 72 character print line. 2. Since the maximum range of zone spacing depends on the PAGE command setting (see Sect. 3.25), it is wise to specify the page width (length of the print line) first and then specify the setting of the tabulation zones. T_E_x_a_m_p_l_e_ * LIST 0010 FOR I=1 TO 10 0020 PRINT I, 0030 NEXT I &_ T_* PAGE=30 * TAB=10 * RUN 1 2 3 4 5 6 7 8 9 10 END AT 0030 * TAB=5 &_ \f T_* RUN 1 2 3 4 5 6 7 8 9 10 END AT 0030 &_* T_ 3.39T_A_B_(_X_)_ _f_u_n_c_t_i_o_n_ F_o_r_m_a_t_ TAB(expr') &_ T_ expr': an expression which is evaluated to an integer. U_s_e_ As a function in PRINT statements (see Sect. 3.24) to tabulate &_the printing position for an item in the argument list to the T_column number evaluated from an expression. R_e_m_a_r_k_s_ 1. As the print line columns are numbered from 0, t_h_e_ _p_o_s_i_t_i_o_n_ &_ i_n_d_i_c_a_t_e_d_ _b_y_ _t_h_e_ _T_A_B_(_X_)_ _f_u_n_c_t_i_o_n_ _i_s_ _a_l_w_a_y_s_ _r_e_l_a_t_i_v_e_ _t_o_ _0_, e.g. the column number indicated by TAB(31) is 30. 2. A PRINT statement may contain several TAB(X) functions, each of which affects only the item in the argument list that immediately follows it. The printing position for this item will depend on the value of expr' and the punctuation (; or ,) following TAB(X). 3. If expr' evaluates to a column number greater than or equal to the current column number and less than the length of the print line, the value of expr' indicates t_h_e_ _n_e_w_ _c_o_l_u_m_n_ p_o_s_i_t_i_o_n_. If TAB(X) is followed by a semicolon (;), the new column position remains unchanged (see Example). If TAB(X) is followed by a comma (,), the new column position is changed to the leftmost position of the next print zone u_n_l_e_s_s_ the new column position coincides with the leftmost position of a print zone (see Example). After determination of the new column position, the item in the argument list immediately following the TAB(X) function is printed (see Remarks in Sect. 3.27).\f 4. If expr' evaluates to a column number less than the current column number, the TAB(X) function is ignored and positioning proceeds as in 3. 5. If expr' evaluates to a column number greater than the length of the print line, expr' is reduced modulo the length of the print line and positioning proceeds as in 3. The length of the print line (width of the page) can be set by means of the PAGE command (see Ch. 3.25). 6. If expr' evaluates to 0, e.g. TAB(0), a carriage return and line feed are output and positioning proceeds as in 3. T_E_x_a_m_p_l_e_ 0010 LET POS=5; NUMBER=-1048 0020 PRINT TAB(POS);NUMBER;TAB(7*POS);NUMBER 0030 PRINT TAB(POS),NUMBER,TAB(7*POS),NUMBER 0040 PRINT TAB(31);NUMBER 0050 STOP 01234567890123456789012345678901234567890123456789012345 -1048 -1048 -1048 -1048 -1048 &_ C_o_m_m_e_n_t_ Shows the use of the semicolon and the comma as spacing characters in conjunction with the TAB(X) function. T_3.40W_H_I_L_E_-_E_N_D_W_H_I_L_E_ F_o_r_m_a_t_ WHILE expr' THEN DO statements' ENDWHILE comment' expr': a relational expression. statements': a block of statements. comment': a text comment. &_ \f U_s_e_ As a statement to execute a block of statements repetitively while the value of an expression is true. T_R_e_m_a_r_k_s_ 1. R_u_l_e_s_ a. expr' is a relational expression whose value is either &_true or false, e.g. I = 10, MONTH 13. b. For every WHILE statement there must be a matching ENDWHILE statement, otherwise the error message 0053: WHILE WITHOUT ENDWHILE is output. c. If the body of a WHILE-ENDWHILE loop is entered at any point other than the WHILE statement, the error message 0054: ENDWHILE WITHOUT WHILE will be output when the ENDWHILE statement corresponding to the skipped WHILE statement is encountered. T_2. P_r_o_g_r_a_m_ _l_o_o_p_ _o_p_e_r_a_t_i_o_n_ a. expr' is evaluated. &_ b. If the value of expr' is false, the termination condition is satisfied and step e is performed. c. statements' is executed. d. Step a is repeated. e. Control passes to the first statement following the corresponding ENDWHILE statement. N_o_t_e_:_ If the value of expr' is false the first time the WHILE statement is encountered, statements' is not executed even once. T_3. N_e_s_t_e_d_ _l_o_o_p_s_ WHILE-ENDWHILE loops may be nested to a depth of seven. 4. The word ENDWHILE may be followed by a comment. &_ \f T_E_x_a_m_p_l_e_ _1_ 0010 LET I=1 0020 WHILE I10 DO 0030 PRINT I; 0040 LET I=I+1 0050 ENDWHILE 0060 PRINT "13'10'AFTER "ENDWHILE" " 0070 STOP 1 2 3 4 5 6 7 8 9 &_AFTER "ENDWHILE" T_E_x_a_m_p_l_e_ _2_ C_o_m_m_e_n_t_ _(_2_)_ 0010 LET I=11 If expr' is false when 0020 WHILE I10 DO WHILE is encountered for the 0030 PRINT "DO NOT ENTER HERE" first time, statements' is 0040 LET I=I-1 not executed even once. 0050 ENDWHILE 0060 PRINT "AFTER "ENDWHILE" " 0070 STOP &_AFTER "ENDWHILE" T_ E_x_a_m_p_l_e_ _3_ C_o_m_m_e_n_t_ _(_3_)_ 0010 LET I=1 Shows nested WHILE-ENDWHILE 0020 WHILE I5 DOloops. 0030 LET J=8 0040 PRINT "I=";I, 0050 WHILE J'I DO 0060 PRINT " J=";J; 0070 LET J=J-1 0080 ENDWHILE 0090 PRINT 0100 LET I=I+1 0110 ENDWHILE 0120 PRINT "AFTER LAST "ENDWHILE" " 0130 STOP I= 1J= 8 J= 7 J= 6 J= 5 J= 4 J= 3 J= 2 I= 2J= 8 J= 7 J= 6 J= 5 J= 4 J= 3 I= 3J= 8 J= 7 J= 6 J= 5 J= 4 I= 4J= 8 J= 7 J= 6 J= 5 &_AFTER LAST "ENDWHILE"\f R_E_S_E_R_V_E_D_ _W_O_R_D_S_ _I_N_ _T_H_E_ _R_C_ _B_A_S_I_C_ _L_A_N_G_U_A_G_E_ The use of the words is denoted by the following abbreviations: AO (arithmetic operator), C (command), F (function), LO (logical operator), NI (not implemented), and S (statement). The section (chapter) number indicates where the sole, first, or principal explanation of the word will be found. W_o_r_d_ U_s_e_ S_e_c_t_i_o_n_ W_o_r_d_ U_s_e_ S_e_c_t_i_o_n_ W_o_r_d_ U_s_e_ S_e_c_t_i_o_n_ ABS F 4.2 FILE S,C 8 RANDOMIZE S,C 3.31 AND LO 2 FNA - FNÅ F 3.5 READ S,C 3.32 ATN F 4.3 FOR S 3.12 REM S 3.33 AUTO C 9.3 RENAME S,C 8.21 GOSUB S 3.13 RENUMBER C 9.15 BATCH C 9.4 GOTO S 3.14 REPEAT S 3.34 BYE C,S 9.5 RESTORE S,C 3.35 RETURN S 3.13 CALL NI IDN S,C 6.8 RND F 4.9 CASE S 3.2 IF S,C 3.15 RUN C 9.16 CHAIN S,C 3.3 INPUT S,C 3.18 RUNL C 9.16 CHANGESIZES,C 8.2 INT F 4.7 CHR F 5.2 INV S,C 6.10 CLAIM S,C 7.2 SAVE C,S 9.17 CLOSE S,C 8.3 KILL C G.2 SCANCLAIM S,C 7.5 CON S,C 6.7 SCOPE S,C 7.6 CON C 9.6 LEN F 5.3 SCRATCH C B.5 CONL C 9.6 LET S,C 3.19 SEARCH S,C 7.7 COPY C,S 8.4 LIST C 9.10 SGN F 4.10 COS F 4.4 LOAD C 9.11 SIN F 4.11 CREATE S,C 8.5 LOCK C G.2 SIZE C 9.17 LOG F 4.8 SOLVE S,C 6.13 DATA S 3.4 LOOKUP C 7.6SQR F 4.12 DEF S 3.5 LOWBOUND 3.20STEP S 3.12 DELAY S 3.6 STOP S 3.37 DELETE S,C 8.6 MAT S,C 6 SYS F 4.13 DET F 6.6 MATER S,C 7 DIGITS S,C 8.7 MESSAGE C 9.12 DIM S,C 3.8 MOD AO 2 TAB C,S 8.21 DISPLAY C 9.7 TAN F 4.14 DIV AO 2 NEW C,S 9.13 THEN S,C 3.15 DO S 3.39 NEWCLAIM C,S 7.4TIME C B.6 NEXT S 3.12 TO S 3.12 ELSE S 3.17 NOT LO 2 TRN S,C 6.14 END S 3.9 TRUE AO 2 ENDCASE S 3.2 OF S 3.2 ENDIF S 3.16 ON S 3.24 UNLOCK C G.2 ENDPROC S 3.29 OPEN S,C 8.14 UNTIL S 3.33 ENDWHILE S 3.39 OR LO 2 USER S,C 7.6 ENTER C,S 9.8 ORD F 5.4 USING S 3.28 EOF F 8.8 EOJ C B.4 PAGE C,S 8.15 WHEN S 3.2 ERR S 3.22 PRINT S,C 3.26 WHILE S 3.40 ESC S 3.23 PRINTDATE S,C 3.28WRITE S,C 8.23 EXEC S 3.11 PRINTEPS S,C 3.29 EXP F 4.5PROC S 3.30 ZER S,C 6.15 PUNCH C 9.14 FALSE AO 2\f \f «eof»