BB___RESTORE

=RESTORE= toc

Description
> RESTORE will reset the reading of DATA statements so that the next READ will get information from the first DATA statement in the program (or the first DATA statement inside a function or subroutine, if this is where the RESTORE is executed).

Syntax

 * 1) restore
 * 2) restore //[branch_label]//

Hints
> > No matter where in your main program listing you place your data statements, data is read into the program > beginning with the first data statement the program encounters and continuing with the next data statement > listed, unless a RESTORE command is encountered. At that point, the program will read data beginning again > with the first data statement in the listing. > > Using a branch label will start reading at the next DATA statement after that branch label - if a RESTORE [branch_label] > is included. Otherwise, data will be read in the normal order of listing. To see this in action, REM out the > restore [morenumbers] in the [morenumbers] branch and run the program again. You should see the data printed > from the second data statement in the main program, numbers 11 to 20. >

Example
code format="lb" dim A(10)                          ' This sets the size of the array to 10 elements

data 1,2,3,4,5,6,7,8,9,10          ' These are the first ten numbers that will be read into the array data 11,12,13,14,15,16,17,18,19,20 for x=1 to 10                      ' This loop reads 10 numbers into the array ...    READ y                          ' It will read the first line of data, numbers 1 to 10. A(x)=y next x

' Normally, the next read command would get it's data from the next data statement, ' which would be numbers 11 to 20 in this case. ' However, using RESTORE [branch_label] will change that behavior.

gosub [morenumbers]                 ' Here we send the program to the subroutine

for x=1 to 10                       ' This loop will PRINT the numbers in the array ... print A(x)                      '  (that were loaded in the subroutine) next x

end

[morenumbers]                      ' This is the subroutine. data 31,32,33,34,35,36,37,38,39,40 data 41,42,43,44,45,46,47,48,49,50

restore [morenumbers]              ' The restore [branch_label] command tells the program to read ' the next data from the first data statement after [branch_label].

for x=1 to 10                      ' This loop reads 10 numbers into the array ... READ y                         ' The read command will read numbers 31 to 40 into the array, A(x)=y                         ' instead of 11 to 20 due to the restore command above. next x return

code

Useful Functions
code format="lb" Place a useful function using this command here code