Olivetti M10 PORTABLE COMPUTER Operations Guide


13.  PROGRAMMING FEATURES

BRANCHES

Within BASIC programs  the  statement  GOTO  n  causes  an  unconditional 
transfer  of  control (branch) to line n, changing the normal sequence of 
execution.

For a conditional transfer of control the following statements are avail-
able:

                IF... THEN... ELSE 
                IF... GOTO... ELSE 
                ON... GOTO

All of these statements can be 'nested' (the process  of  introducing  an 
activity  within  an  activity) and details of the format of these state-
ments are given in Chapter 15.

LOOPS

Program loops for  repetitive  operations  can  be  generated  using  the 
FOR... NEXT  statement.  Loops can be nested in the same way as branches, 
the limitation being the available memory. A NEXT statement may  conclude 
nore  than one loop if the inner loop terminates at the same point as the 
outer loop. There is no error condition for a FOR without a matching NEXT 
statement,  but  if a NEXT is used without a preceding FOR the error code 
NF is displayed.

SUBROUTINES

A subroutine may be used to allow the same sequence of instructions to be 
carried  out at any point in a program.  The statement GOSUB n causes the 
progran .a junp to line n ahd to continue with execution of  the  subrou-
tine which starts at line n. The last statement of the subroutine must be 
RETURN which  transfers  orogram  control  back  to  the  line  following 
GOSUB n.

M10 Operations Guide	13-1

MACHINE LANGUAGE SUBROUTINES A machine language subroutine can be used within a BASIC program by using the CALL statement to invoke the particular program required. A few of the subroutiness availahle cannot be started with a CALL statement; see CALL in the Directory of BASIC commands (Chapter 15). 13-2
14. FILES Files can contain programs or data. BAS1C program files are automatically assigned the suffix .BA, whereas TEXT files and BASIC data files have the suffix .DO. Machine languaqe program files have the suffix .CO. All data files are in a sequential form. Normally they are created in memory; they can then be transferred to a cassette tape or another peripheral. It is possible to write a file directly onto cassette but it is not possible to append data onto a cassette file. Anything written to a cassette file overwrites the original. To read or write to a data file it must first be opened using the statement OPEN. OPENING A FILE The OPEN statement is used to specify the direction of data transferred. To read a file it must be opened in input mode, and to write to a file it must be opened in output mode. Data files in memory can be opened in the append mode where anything written to the file is added to the existing file and the original is not lost. A file in memory can be transferred to cassette tape using the SAVE statement, and a file on tape can be transferred to memory using LOAD. A number is allocated to the program or data file as part of the OPEN statement. The number allocated for a particular mode cannot be used for another anode unless the file is first closed. READING A DATA FILE Data from a file can be used in a program by first opening the file in input mode, and then using the INPUT statement to extract the items of data and assign them to program variables. The EOF statement must be used after TNPUT to detect the end of the file. If this is not done an EF error will be displayed when the end of the file is reached and the program will terminate in an uncontrolled way. M10 Operations Guide 14-1
WRITING A DATA FILE Data can be written to a file by first opening the file in output mode, and then using the PRINT or PRINT USING statements. CLOSING A FILE Some statements and comnands will automatically close all open files, e.g. END. To close a file independently of these the CLOSE statement is available. 14-2