← All lessons

LESSON 4 OF 13

GOTO, GOSUB AND STRUCTURE

Jumping around the program, and coming back.

GOTOGOSUBRETURNIF THENEND

GOTO 10 jumps to line 10 and carries on from there. It is how BASIC loops and menus are built, and how programs become spaghetti if you aren't careful.

GOSUB 100 jumps to line 100 too, but remembers where it came from. When the computer meets RETURN it goes back to the statement after the GOSUB. That lets you write a routine once and call it from many places — a subroutine.

IF condition THEN statement runs the statement only when the condition is true. IF C=3 THEN END stops the program. There is no ELSE in BASIC V2; use another IF.

LESSON 416 lines

Type with the keyboard under the screen, or tap the blue screen to use your phone's own keyboard. While a program runs, keys go to INPUT and GET. When it says READY., type a line and press RETURN to run it straight away.