Fast Track 1.4

From BR Wiki
Revision as of 18:26, 10 September 2014 by Laura (talk | contribs) (→‎Program Flow)
Jump to navigation Jump to search

Program Flow

As your program grows, there are several pieces of BR for handling the flow and order of your programs.

00070 GOTO 800 

will go to line 800. A better habit is to use line labels because line numbers may change. For example

00070 GOTO finalprint

00900 finalprint: ! This is the final print page...

Gosub is another way to move through your program. It uses RETURN to get back to the line after it initiated it.

00070 GOSUB printheader

will send you through a subroutine, for example

00900 printheader: print fields using “8,16,cc 50”: “Smart Software Inc”
00910 RETURN

Gosubs must always end in a return, which will send the flow back up to the line after the GOSUB statement.

DO LOOP

Looping can be done WHILE or UNTIL another condition is met. Do Loops are often used to read or write data.

An internal function FILE returns the status on a data file operation. So looping WHILE FILE(filename)=0 , since 0 is the function's return when a file is read properly, will continue through the loop until the end of the file has been reached.

Loops can be nested, as you see in the following example for reading records into two MATs.

do while file(GHSC)=0
     read #2, using readform$ : mat MaterialRec$, mat MaterialRec eof Ignore
          if file(MaterialRec$)=0 then
             if MaterialRec$(recipecode)=Rec$(recipecode) and MaterialRec(version)=Rec(version) then
                print #PN: MaterialRec$(gc_hcode)&"[POS(+0,8)]"&MaterialRec$(gc_hstmt)
             end if
          end if
loop while MaterialRec$(recipecode)=Rec$(grecipecode) and MaterialRec(version)=Rec(version)