PRINT# |
P.# |
The format of the variables as written to the file differs from the format used on the BBC Micro. All numeric values are written as five bytes of binary real data (see the Annex entitled Format of Program and Variables in Memory). Strings are written as the bytes in the string (in the correct order) plus a carriage return.PRINT#E,A,B,C,D$,E$,F$ PRINT#4,prn$
Before you use this statement, you must normally have opened a file using OPENOUT or OPENUP. PRINT# may alternatively be used with the AUX device (usually a serial port), which has the 'permanently open' handle = 3, or the PRN device (usually a parallel port) which has the 'permanently open' handle = 4.
You can use PRINT# to write data (numbers and strings) to a data file in the 'standard' manner. If you wish to 'pack' your data in a different way, you should use BPUT#. You can use PRINT# and BPUT# together to mix or modify the data format. For example, if you wish to write a 'compatible' text file, you could PRINT# the string and BPUT# a line-feed. This would write the string followed by a carriage-return and a line-feed to the file.
Remember, with BBC BASIC (Z80) the format of the file is completely under your control.
PRINT#<numeric>{,<numeric>|<str>}
PRINT, OPENUP, OPENOUT, CLOSE#, INPUT#, BPUT#, BGET#, GET$, EXT#, PTR#, EOF#
If there are spaces between the procedure name and the opening bracket of the parameter list (if any) they must be present both in the definition and the call. It's safer not to have spaces between the procedure name and the opening bracket.
A procedure may be defined with any number of parameters of any type.
A procedure definition is terminated by ENDPROC.
A procedure does not have to be declared before it is called.
Procedures are re-entrant and the parameters (arguments) are passed by value.
See the Procedures and Functions sub-section for more details.10 INPUT"Number of discs "F 20 PROC_hanoi(F,1,2,3) 30 END 40 : 50 DEF PROC_hanoi(A,B,C,D) 60 IF A=0 THEN ENDPROC 70 PROC_hanoi(A-1,B,D,C) 80 PRINT"Move disk ";A" from ";B" to ";C 90 PROC_hanoi(A-1,D,C,B) 100 ENDPROC
PROC<name>[(<exp>{,<exp>})]
DEF, ENDPROC, LOCAL
Reading or writing (using BGET#, BPUT#, GET$, INPUT# or PRINT#) takes place at the current position of the pointer. The pointer is automatically updated following a read or write operation.PTR#F=PTR#F+5 :REM Move pointer to next number PTR#F=recordnumber*recordlength
You can use PTR# to select which item in a file is to be read or written to next. In a random file (see the section on BBC BASIC (Z80) Disk Files) you use PTR# to select the record you wish to read or write.
If you wish to move about in a file using PTR# you will need to know the precise format of the data in the file.
A file opened with OPENUP may be extended by setting its pointer to its end (PTR#fnum = EXT#fnum) and then writing to it. If you do this, you must remember to CLOSE the file when you have finished with it in order to update the directory entry.
By using PTR# you have complete control over where you read and write data in a file. This is simple concept, but it may initially be difficult to grasp its many ramifications. The BBC BASIC (Z80) Disk Files section has a number of examples of the use of PTR#.
PTR#<numeric>=<numeric> <n-var>=PTR#<numeric>
OPENIN, OPENUP, OPENOUT, CLOSE#, PRINT#, INPUT#, BPUT#, BGET#, GET$, EXT#, EOF#
This instruction gives direct access from BBC BASIC (Z80) to the computer's I/O hardware. Typically, you can use it to directly access I/O ports.PUT A,N :REM output N to port A.
PUT <numeric>,<numeric>
GET
QUIT [<numeric>]
END, STOP
Unlike humans, BBC BASIC (Z80) wants angles expressed in radians. You can use this function to convert an angle expressed in degrees to radians before using one of the angle functions (SIN, COS, etc).X=RAD(Y) X=SIN RAD(90)
Using RAD is equivalent to multiplying the degree value by PI/180, but the result is calculated internally to a greater accuracy.
See COS, SIN and TAN for further examples of the use of RAD.
<n-var>=RAD<numeric>
DEG
In many of your programs, you will want to use data values which do not change frequently. Because these values are subject to some degree of change, you won't want to use constants. On the other hand, you won't want to input them every time you run the program either. You can get the best of both worlds by declaring these values in DATA statements at the beginning or end of your program and READing them into variables in your program.READ C,D,A$
A typical use for DATA and READ is a name and address list. The addresses won't change very often, but when they do you can easily amend the appropriate DATA statement.
See DATA for more details and an example of the use of DATA and READ.
READ <n-var>|<s-var>{<n-var>|<s-var>}
DATA, RESTORE
A statement which draws an outline rectangle or a filled rectangle. RECTANGLE is followed by the X and Y coordinates of the bottom left-hand corner of the rectangle then the width and height of the rectangle. To draw a square you can omit the fourth parameter; the height is then assumed to be the same as the width. To draw a filled (solid) rectangle or square use RECTANGLE FILL.
The rectangle is drawn in the current graphics foreground colour. This colour can be changed using the GCOL statement.
RECTANGLE can also be used to copy or move a rectangular area of the screen to a different place. In this case RECTANGLE is followed by the X and Y coordinates of the bottom left-hand corner of the source rectangle, the width and height of the rectangle, the keyword TO and finally the X and Y coordinates of the bottom left-hand corner of the destination rectangle. To move the rectangle rather than copy it, use RECTANGLE FILL. To swap two rectangular areas use RECTANGLE SWAP.
RECTANGLE is also used in the MOUSE RECTANGLE statement.RECTANGLE xpos,ypos,width,height RECTANGLE FILL 400,500,200 RECTANGLE 100,100,200,200 TO 300,300 RECTANGLE FILL srcx,srcy,dx,dy TO dstx,dsty RECTANGLE SWAP x1,y1,dx,dy TO x2,y2
RECTANGLE [FILL] <numeric>,<numeric>,<numeric>[,<numeric>] [TO <numeric>,<numeric>] RECTANGLE SWAP <numeric>,<numeric>,<numeric>[,<numeric>] TO <numeric>,<numeric>
FILL, MOUSE, SWAP, TO
You can use the REM statement to put remarks and comments in to your program to help you remember what the various bits of your program do. BBC BASIC (Z80) completely ignores anything on the line following a REM statement.
You will be able to get away without including any REMarks in simple programs. However, if you go back to a lengthy program after a couple of months you will find it very difficult to understand if you have not included any REMs.
If you include nothing else, include the name of the program, the date you last revised it and a revision number at the start of your program.
10 REM WSCONVERT REV 2.30 20 REM 5 AUG 84 30 REM Converts 'hard' carriage-returns to 'soft' 40 REM ones in preparation for use with WS.
REM any text
None
RENUMBER |
REN. |
The options are as for AUTO, but increments of greater than 255 are allowed.
You can specify both the new first number (n1) and/or the step size (s). The default for both the first number and the step size is 10. The two parameters should be separated by a comma or a hyphen.
For example:RENUMBER RENUMBER n1 RENUMBER n1,s RENUMBER ,s
RENUMBER produces error messages when a cross reference fails. The line number containing the failed cross-reference is renumbered and the line number in the error report is the new line number.
RENUMBER First number 10, step 10 RENUMBER 1000 First number 1000, step 10 RENUMBER 1000-5 First number 1000, step 5 RENUMBER ,5 First number 10, step 5 RENUMBER -5 First number 10, step 5
If you renumber a line containing an ON GOTO/GOSUB statement which has a calculated line number, RENUMBER will correctly cope with line numbers before the calculated line number. However, line numbers after the calculated line number will not be changed.
In the following example, the first two line numbers would be renumbered correctly, but the last two would be left unchanged.
RENUMBER may be used in a program, but it will exit to the command mode on completion.ON action GOSUB 100,200,(type*10+300),400,500
RENUMBER [<n-const>[,<n-const>]]
LIST
REPEAT |
REP. |
The purpose of a REPEAT...UNTIL loop is to make BBC BASIC (Z80) repeat a set number of instructions until some condition is satisfied.
You must not exit a REPEAT...UNTIL loop with a GOTO. If you jump out of a loop with a GOTO (How could you!!!) you should jump back in. If you must jump out of the loop, you should use UNTIL TRUE to 'pop' the stack. For (a ghastly) example:REPEAT UNTIL GET=13 :REM wait for CR X=0 REPEAT X=X+10 PRINT "What do you think of it so far?" UNTIL X>45
See the keyword UNTIL for ways of using REPEAT...UNTIL loops to replace unconditional GOTOs for program looping.10 i=1 20 REPEAT: REM Print 1 to 100 unless 30 I=I+1: REM interrupted by the 40 PRINT i: REM space bar being pressed 50 x=INKEY(0): REM Get a key 60 IF x=32 THEN 110:REM exit if <SPACE> 70 UNTIL i=100 80 PRINT "****" 90 END 100 : 110 UNTIL TRUE: REM Pop the stack 120 PRINT "Forced exit":REM Carry on with program 130 FOR j=1000 TO 1005 140 PRINT j 150 NEXT 160 END
See the sub-section on Program Flow Control in the General Information section for more details on the working of the program stack.
REPEAT
UNTIL
You can use these keywords within your own error handling routines to print out or process an error message for those errors you are not able to cope with.
The example below is an error handling routine designed to clear the screen before reporting the error:
See the sub-section on Error Handling and the keywords ERR, ERL and ON ERROR for more details.ON ERROR MODE 3 : REPORT : PRINT " at line ";ERL : END
REPORT <s-var> = REPORT$
ERR, ERROR, ERL, ON ERROR
RESTORE |
RES. |
RESTORE on its own resets the data pointer to the first data item in the program.
RESTORE followed by a line number sets the data pointer to the first item of data in the specified line (or the next line containing a DATA statement if the specified line does not contain data). This optional parameter for RESTORE can specify a calculated line number.
(BBC BASIC version 5 or later only)
RESTORE followed by a plus sign (+) and a positive numeric value sets the
data pointer to the first item of data in the line offset from the line containing
the RESTORE statement by the specified number of lines (or the next
DATA statement if the specified line does not contain any data).
You can use RESTORE to reset the data pointer to the start of your data in order to re-use it. alternatively, you can have several DATA lists in your program and use RESTORE to set the data pointer to the appropriate list.RESTORE RESTORE 100 RESTORE +2 RESTORE (10*A+20) RESTORE (mydata)
RESTORE DATA causes the DATA pointer saved by a previous LOCAL DATA statement to be restored from the stack.
RESTORE ERROR causes the error-trapping status saved by a previous ON ERROR LOCAL statement to be restored from the stack.
RESTORE [<l-num>] RESTORE [(<numeric>)] RESTORE +<numeric> RESTORE DATA RESTORE ERROR
READ, DATA, ON ERROR LOCAL
RETURN |
R. |
You use RETURN at the end of a subroutine to make BBC BASIC (Z80) return to the place in your program which originally 'called' the subroutine.
You may have more than one return statement in a subroutine, but it is preferable to have only one entry point and one exit point (RETURN).
Try to structure your program so you don't leave a subroutine with a GOTO. If you do, you should always return to the subroutine and exit via the RETURN statement. If you insist on using GOTO all over the place, you will end up confusing yourself and maybe confusing BBC BASIC (Z80) as well. The sub-section on Program Flow Control explains why.
(BBC BASIC version 5 or later only)RETURN
GOSUB, ON GOSUB
(BBC BASIC version 5 or later only)
RIGHT$ may also be used to the
left of an equals sign to change the end of a string whilst leaving the rest alone.
There must not be any spaces between the RIGHT$ and the opening bracket.
For example,A$ = RIGHT$(A$,num) A$ = RIGHT$(A$,2) A$ = RIGHT$(LEFT$(A$,3),2) RIGHT$(A$,3) = B$
would printname$="BBC BASIC for Z80" FOR i=3 TO 13 PRINT RIGHT$(name$,i) NEXT END
When using RIGHT$ on the left of an equals sign, and the expression to the right of the equals sign evaluates to a string with fewer characters than the specified sub-string length, only that number of characters is changed. For example:Z80 Z80 r Z80 or Z80 for Z80 for Z80 C for Z80 IC for Z80 SIC for Z80 ASIC for Z80 BASIC for Z80
will set A$ equal to "BBC BASZZ". Although the sub-string length is set to four, only the last two characters are actually modified since that is the length of the string "ZZ".A$ = "BBC BASIC" RIGHT$(A$,4) = "ZZ"
(BBC BASIC version 5 or later only)
RIGHT$(A$) is shorthand for RIGHT$(A$,1),
in other words it returns or sets the last character of A$.
<s-var>=RIGHT$(<string>[,<numeric>]) RIGHT$(<s-var>[,<numeric>])=<string>
LEFT$, MID$, INSTR
If n is negative the pseudo random sequence generator is set to a number based on n and n is returned.
RND returns a random integer 1 - &FFFFFFFF. RND(n) returns an integer in the range 1 to n (n>1). RND(1) returns a real number in the range 0.0 to .99999999.
If n is 0 the last random number is returned in RND(1) format.
The random number generator is initialised by RUN (or CHAIN). Consequently, RND will return zero until the RUN (or CHAIN) command is first issued.X=RND(1) X%=RND N=RND(6)
<n-var>=RND[(<numeric>)]
None
RUN is a statement and so programs can re-execute themselves.RUN
All variables except @% to Z% are CLEARed by RUN.
If you want to start a program without clearing all the variables, you can use the statement
where nnnn is number of the line at which you wish execution of the program to start.GOTO nnnn
RUN "filename" can be used as an alternative to CHAIN "filename".
RUN
NEW, OLD, LIST, CHAIN
SAVE |
SA. |
You use SAVE to save your program for use at a later time. The program must be given a name (file-specifier) and this name becomes the name of the file in which your program is saved.SAVE "FRED.BBC" SAVE A$
The name (file-specifier) must follow the normal CP/M-80 naming conventions. See the Operating System Interface section for a description of a file-specifier (name).
Unless a different extension is specified in the file-specifier, .BBC is automatically used. Thus,
would save the current program to a file called FRED.BBC in the current directory.SAVE "FRED"
If you want to exclude the extension, include the full-stop in the file name, but don't follow it with anything. For example, to save a program to a file called 'FRED', type,
SAVE "FRED."
SAVE <str>
LOAD, CHAIN
You can use this function to determine whether a number is positive, negative or zero.X=SGN(Y) result=SGN(answer)
SGN returns:
+1 for positive numbers 0 for zero -1 for negative numbers
<n-var>=SGN(<numeric>)
ABS
This function returns the sine of an angle. The angle must be expressed in radians, not degrees.X=SIN(Y)
Whilst the computer is quite happy dealing with angles expressed in radians, you may prefer to express angles in degrees. You can use the RAD function to convert an angle from degrees to radians.
The example below sets Y to the sine of the angle 'degree_angle' expressed in degrees.
Y=SIN(RAD(degree_angle))
<n-var>=SIN(<numeric>)
COS, TAN, ACS, ASN, ATN, DEG, RAD
Not implemented in the generic CP/M version of BBC BASIC (Z80)
SOUND <numeric>,<numeric>,<numeric>,<numeric>
ENVELOPE
SPC can only be used within a PRINT or INPUT statement.
PRINT DATE;SPC(6);SALARY INPUT SPC(10) "What is your name ",name$
PRINT SPC(<numeric>) INPUT SPC(<numeric>)
TAB, PRINT, INPUT
If you attempt to calculate the square root of a negative number, a '-ve root' error will occur. You could use error trapping to recover from this error, but it is better to check that the argument is not negative before using the SQR function.X=SQR(Y)
<n-var>=SQR(<numeric>)
None
STEP |
S. |
The step may be positive or negative. STEP is optional; if it is omitted, a step size of +1 is assumed.FOR i=1 TO 20 STEP 5
You can use this optional part of the FOR...TO...STEP...NEXT structure to specify the amount by which the FOR...NEXT loop control variable is changed each time round the loop. In the example below, the loop control variable, 'cost' starts as 20, ends at 5 and is changed by -5 each time round the loop.
10 FOR cost=20 TO 5 STEP -5 20 PRINT cost,cost*1.15 30 NEXT
FOR <n-var>=<numeric> TO <numeric> [STEP <numeric>]
FOR, TO, NEXT
You can use STOP at various places in your program to aid debugging. If your program is going wrong, you can place STOP commands at various points to see the path taken by your program. (TRACE is generally a more useful aid to tracing a program's flow unless you are using formatted screen displays.)
Once your program has STOPped you can investigate the values of the variables to find out why things happened the way they did.
STOP DOES NOT CLOSE DATA FILES. If you use STOP to exit a program for debugging, CLOSE all the data files before RUNning the program again. If you don't you will get some most peculiar error messages.
STOP
END
If the most significant byte of @% is not zero, STR$ uses the current @% description when generating the string. If it is zero (the initial value) then the G9 format (see PRINT) is used.
If STR$ is followed by ~ (tilde) then a hexadecimal conversion is carried out.
The opposite function to STR$ is performed by the VAL function.A$=STR$(PI) B$=STR$~(100) :REM B$ will be "64"
<s-var>=STR$[~](<numeric>)
VAL, PRINT
You can use this function to print repeated copies of a string. It is useful for printing headings or underlinings. The last example for PRINT uses the STRING$ function to print the column numbers across the page. For example,A$=STRING$(N,"hello") B$=STRING$(10,"-*-") C$=STRING$(Z%,S$)
would printPRINT STRING$(4,"-=*=-")
and-=*=--=*=--=*=--=*=-
would printPRINT STRING$(3,"0123456789")
012345678901234567890123456789
<s-var>=STRING$(<numeric>,<str>)
None
The above program segment will print the value 55, being the sum of the eleven values in the array marks%(10).DIM marks%(10) marks%() = 0,1,2,3,4,5,6,7,8,9,10 PRINT SUM(marks%())
If the array has more than one dimension, all the elements in all the dimensions are summed:
This will print the value 201.06193, being PI * 64 (64 being the number of elements in the 8 x 8 array).DIM grid(7,7) grid() = PI PRINT SUM(grid())
<n-var>=SUM(<n-array()>) <s-var>=SUM(<s-array()>) <n-var>=SUMLEN(<s-array()>)
DIM
A statement which swaps (exchanges) the contents of two variables or two arrays. The variables or arrays must be of the same type, for example two integer numeric variables, or two string arrays. If the types differ, a Type mismatch error will result. If two arrays are swapped, their dimensions are also swapped.
SWAP a,b SWAP Coat$,Hat$ SWAP A$(),B$()
SWAP <n-var>,<n-var> SWAP <s-var>,<s-var> SWAP <array()>,<array()>
DIM, RECTANGLE
A statement which calls an Operating System API (Application Program Interface) function or a function in a Shared Object (e.g. a DLL). SYS is followed by the function's address or the function's name as a (case sensitive) string plus, optionally, a list of comma-separated numeric or string parameters to be passed to the function. A 32-bit integer value may be returned from the function by adding TO followed by a numeric variable name.
SYS "FunctionName", parameter, list SYS "FunctionName", parameter, list TO result%
SYS <numeric>|<string> {,<numeric>|<string>} [TO <n-var>] <n-var>=SYS(<string>)
CALL
There are two versions of TAB: TAB(X) and TAB(X,Y) and they are effectively two different keywords.
TAB(X) is a printer orientated statement. The number of printable characters since the last new-line (COUNT) is compared with X. If X is equal or greater than COUNT, sufficient spaces to make them equal are printed. These spaces will overwrite any characters which may already be on the screen. If X is less than COUNT, a new-line will be printed first.
TAB(X,Y) is a screen orientated statement. It will move the cursor on the screen to character cell X,Y (column X, row Y) if possible. No characters are overwritten and COUNT is NOT updated. Consequently, a TAB(X,Y) followed by a TAB(X) will give unpredictable (at first glance) results.
The leftmost column is column 0 and the top of the screen is row 0.
PRINT TAB(10);A$ PRINT TAB(X,Y);B$
PRINT TAB(<numeric>[,<numeric>]) INPUT TAB(<numeric>[,<numeric>])
POS, VPOS, PRINT, INPUT
TAN |
T. |
This function returns the tangent of an angle. The angle must be expressed in radians, not degrees.X = TAN(Y)
Whilst the computer is quite happy dealing with angles expressed in radians, you may prefer to express angles in degrees. You can use the RAD function to convert an angle from degrees to radians.
The example below sets Y to the tangent of the angle 'degree_angle' expressed in degrees.
Y=TAN(RAD(degree_angle))
<n-var>=TAN<numeric>
COS, SIN, ACS, ATN, ASN, DEG, RAD
THEN |
TH. |
You need to use THEN if it is:IF A=B THEN 3000 IF A=B THEN PRINT "Equal" ELSE PRINT "Help" IF A=B THEN PRINT "Equal" ELSE PRINT "Help" ENDIF
IF a=b THEN 320
IF a=b THEN *DIR
IF a=b THEN TIME=0
IF a=b THEN PRINT "Equals" ENDIF
When THEN introduces a multi-line IF ... ENDIF statement it must be the very last thing on the line, not even followed by a REMark.DEF FN_test(a,b,num) IF (a>b) THEN =num =num/256
THEN may be followed immediately by a semicolon (;) to aid translation of the ELSEIF keyword available in some other BASIC dialects, for example:
This facility is intended for use only by automatic translators, rather than in new programs.IF condition1 THEN PROCone ELSEIF condition2 THEN; PROCtwo ELSEIF condition3 THEN; PROCthree ENDIF
IF <t-cond> THEN <stmt>{:<stmt>} [ELSE <stmt>{:<stmt>}] IF <t-cond> THEN ELSEIF <t-cond> THEN;
IF, ELSE, ENDIF
TIME |
TI. |
The following example is a simple program to provide a 24 hour clock. Lines 20 to 40 get the correct time, lines 50 and 60 calculate the number of centi-seconds and set TIME, and lines 110 to 130 convert the value in TIME to hours, minutes and seconds. Line 90 stops the time being printed unless it has changed by at least one second.X=TIME TIME=100
10 CLS 20 INPUT "HOURS ",H 30 INPUT "MINUTES ",M 40 INPUT "SECONDS ",S 50 PRINT "PUSH ANY KEY TO SET THE TIME ";:X=GET 60 TIME=((H*60+M)*60+S)*100 70 T=0 80 REPEAT 90 IF TIME DIV 100=T DIV 100 THEN 150 100 T=TIME 110 S=(T DIV 100) MOD 60 120 M=(T DIV 6000) MOD 60 130 H=(T DIV 360000) MOD 24 140 PRINT TAB(0,23) H;":";M;":";S; 150 UNTIL FALSE
TIME=<numeric> <n-var>=TIME
A keyword which sets and/or returns an extended colour value. On systems which use a colour palette TINT may optionally be used to specify a colour in terms of its RGB (red, green and blue) components. For more details see the documentation of your specific system.
PLOT, DRAW, MOVE, GCOL, POINT
For example,
will print10 FOR i=1 TO 5 STEP 1.5 20 PRINT i 30 NEXT 40 PRINT "**********" 50 PRINT i
Irrespective of the initial value of the loop control variable and the specified terminating value, the loop will execute at least once. For example,1 2.5 4 ********** 5.5
will print10 FOR i= 20 TO 10 20 PRINT i 30 NEXT
20
FOR <n-var>=<numeric> TO <numeric> [STEP <numeric>]
FOR, NEXT, STEP
The length of your program is given by TOP-PAGE.
PRINT TOP-PAGE
<n-var>=TOP
PAGE, HIMEM, LOMEM
TRACE |
TR. |
TRACE X sets a limit on the size of line numbers which will be printed out. Only those line numbers less than X will appear. If you are careful and place all your subroutines at the end of the main program, you can display the main structure of the program without cluttering up the trace with the subroutines.
TRACE OFF turns trace off. TRACE is also turned off if an error is reported or you press <Esc>.
Line numbers are printed as the line is entered. For example,
would trace as10 FOR Z=0 TO 2:Q=Q*Z:NEXT 20 END
whereas[10] [20] >_
would trace as10 FOR Z=0 TO 2 20 Q=Q*Z:NEXT 30 END
and[10] [20] [20] [20] [30] >_
would trace as10 FOR Z=0 TO 3 20 Q=Q*Z 30 NEXT 40 END
[10] [20] [30] [20] [30] [20] [30] [40] >_
TRACE ON|OFF|<l-num> TRACE ON|OFF|(<numeric>)
None
BBC BASIC (Z80) does not have true Boolean variables. Instead, numeric variables are used and their value is interpreted in a 'logical' manner. A value of 0 is interpreted as false and NOT FALSE (in other words, NOT 0 (= -1)) is interpreted as TRUE.10 flag=FALSE .... 100 IF answer$=correct$ flag=TRUE .... 150 IF flag PROC_got_it_right ELSE PROC_wrong
In practice, any value other than zero is considered TRUE. This can lead to confusion; see the keyword NOT for details.
See the Variables sub-section for more details on Boolean variables and the keyword AND for logical tests and their results.
<n-var>=TRUE
FALSE
UNTIL |
U. |
You can use a REPEAT...UNTIL loop to repeat a set of program instructions until some condition is met.
If the condition associated with the UNTIL statement is never met, the loop will execute for ever. (At least, until <Esc> is pressed or some other error occurs.)
The following example will continually ask for a number and print its square. The only way to stop it is by pressing <Esc> or forcing a 'Too big' error.
Since the result of the test z=0 is ALWAYS FALSE, we can replace z=0 with FALSE. The program now becomes:10 z=1 20 REPEAT 30 INPUT "Enter a number " num 40 PRINT "The square of ";num;" is ";num*num 50 UNTIL z=0
This is a much neater way of unconditionally looping than using a GOTO statement. The program executes at least as fast and the section of program within the loop is highlighted by the indentation.20 REPEAT 30 INPUT "Enter a number " num 40 PRINT "The square of ";num;" is ";num*num 50 UNTIL FALSE
See the keyword REPEAT for more details on REPEAT...UNTIL loops. See the Variables sub-section for more details on Boolean variables and the keyword AND for logical tests and their results.
UNTIL <t-cond>
REPEAT
USR calls the machine code subroutine whose start address is its argument. The processor's A, B, C, D, E, F, H and L registers are initialised to the least significant words of A%, B%, C%, D%, E%, F%, H% and L% respectively (see also CALL).
USR provides you with a way of calling a machine code routine which is designed to return one integer value. Parameters are passed via the processor's registers and the machine code routine returns a 32-bit integer result composed of the processor's HLH'L' registers.
Unlike CALL, USR returns a result. Consequently, you must assign the result to a variable. It may help your understanding if you look upon CALL as the machine code equivalent to a PROCedure and USR as the equivalent to Function.X=USR(lift_down)
<n-var>=USR(<numeric>)
CALL
VAL makes the best sense it can of its argument. If the argument starts with numeric characters (with or without a preceding sign), VAL will work from left to right until it meets a non numeric character. It will then 'give up' and return what it has got so far. If it can't make any sense of its argument, it returns zero.X=VAL(A$)
For example,
would printPRINT VAL("-123.45.67ABC")
and-123.45
would printPRINT VAL("A+123.45")
VAL will NOT work with hexadecimal numbers. You must use EVAL to convert hexadecimal number strings.0
<n-var>=VAL(<str>)
STR$, EVAL
VDU |
V. |
A 16-bit value can be sent if the value is followed by a ';'. It is sent as a pair of characters, least significant byte first.
It is very important that the correct number of bytes be sent, as appropriate for the particular VDU command. If too few are sent, the 'remaining' bytes will be taken from subsequent VDU or PRINT statements, sometimes with (at first sight) extremely strange results. In BBC BASIC version 5 or later only this problem can be circumvented by terminating the VDU statement with the '|' character which ensures that sufficient bytes are sent.
The bytes sent using the VDU statement do not contribute to the value of COUNT, but may well change POS and VPOS.VDU 8,8 :REM cursor left two places. VDU &0A0D;&0A0D; :REM CRLF twice VDU 23,1,0| : REM disable cursor
You can use VDU to send characters direct to the current output stream without having to use a PRINT statement. It offers a convenient way of sending a number of control characters to the console or printer.
VDU <numeric>{,|;<numeric>}[;]
CHR$
You can use VPOS in conjunction with POS to return to the present position on the screen after printing a message somewhere else. The example below is a procedure for printing a 'status' message at line 23. The cursor is returned to its previous position after the message has been printed.Y=VPOS
1000 DEF PROC_message(message$) 1010 LOCAL x,y 1020 x=POS 1030 y=VPOS 1040 PRINT TAB(0,23) CHR$(7);message$; 1050 PRINT TAB(x,y); 1060 ENDPROC
<n-var>=VPOS
POS
A statement causing the program to pause for the specified number of centiseconds (hundredths of a second), or to wait for a Vertical Sync (retrace) event.
This causes the program to pause for approximately one second.WAIT 100
WAIT 0 optionally results in only a short pause (typically about 1 millisecond), but does give other programs an opportunity to run; it can be useful in preventing your program consuming 100% of the processor's time.
WAIT without a parameter optionally waits for a Vertical Sync (retrace) event, if this is possible.
WAIT [<numeric>]
INKEY, TIME
A keyword which is part of the CASE... ENDCASE clause. WHEN precedes the value (or values) against which the CASE variable is tested. WHEN must be the first item on the program line.
CASE die% OF WHEN 1,2,3 : bet$ = "lose" WHEN 4,5,6 : bet$ = "win" OTHERWISE bet$ = "cheat" ENDCASE
WHEN <numeric>{,<numeric>} : {<stmt>} WHEN <string>{,<string>} : {<stmt>}
CASE, OF, OTHERWISE
A statement which is the starting point of a WHILE...ENDWHILE loop.
The purpose of a WHILE...ENDWHILE loop is to make BBC BASIC repeat a set number of instructions while some condition is satisfied. The difference between a WHILE...ENDWHILE loop and a REPEAT...UNTIL loop is that the instructions within a REPEAT...UNTIL loop are always executed at least once (the test for completion is performed at the end of the loop) whereas the instructions within a WHILE...ENDWHILE loop are not executed at all if the condition is initially FALSE (the test is performed at the start of the loop).
You must not exit a WHILE...ENDWHILE loop with a GOTO; you can force a premature end to the loop with the EXIT WHILE statement.WHILE LEFT$(A$,1)=" " A$=MID$(A$,2) : REM Remove leading spaces ENDWHILE
WHILE...ENDWHILE loops may be nested.
WHILE <t-cond>
ENDWHILE, EXIT, REPEAT
WIDTH |
W. |
If the specified width is zero (the initial value) the interpreter will not attempt to control the overall line width.WIDTH 80
WIDTH n will cause the interpreter to force a new line after n MOD 256 characters have been printed; it also affects output to the printer.
(BBC BASIC version 5 or later only)
WIDTH can also be used as a function. It returns the current line width.
WIDTH <numeric> <n-var> = WIDTH
COUNT
CONTENTS |
CONTINUE |