Program flow


Lines in a BASIC program are always executed , starting from the top of the file. In the below example first line 10 is executed , then line 20, and line 21 tells the program to stop. Each line must start with a BASIC line number in increasing order. It is a standard practice to leave space for extra lines. The editor will, if possible increment by 10, when adding a new line.
10 PRINT "Hello"
20 PRINT "Have a nice day"
21 END 

Control Structure

A control structure is used to test if something is true or false, such as is 2 larger than 4.

IF THEN

 Syntax:

    IF condition THEN do something
10 IF 2 > 4 THEN PRINT "Wrong answer"
20 IF  A+B = 4 THEN GOTO 200
30 IF  A+B > 4 * COS(V) THEN COLOR = BLUE
                    

Jump

It is possible to jump to another part of the screen using GOTO or GOSUB.

GOTO

Jump to a line number. The line number can be a variable, but this cannot be recommended.

 Syntax:

    GOTO number
10 GOTO 200
20 IF X > 10 THEN GOTO 300

GOSUB and RETURN

Jump to a line number, and use RETURN to return to the line after the GOSUB line.

 Syntax:

    GOSUB number
10 GOSUB 200
20 PRINT "I am back from the subroutine"
30 ....
...
200 PRINT "I am in a subroutine"
210 LET X = X + 2
210 RETURN

The screen output will be:
I am in a subroutine
I am back from the subroutine
_
Next