Usein kysyttyjä kysymyksiä

How do I use subroutines with GOSUB and RETURN?
Viimeeksi Päivitetty 1 päivää sitten

Subroutines: GOSUB and RETURN

Subroutines let you reuse code without repeating it. Jump to a routine, do the work, and return!

Basic Syntax

10 PRINT "MAIN PROGRAM"
20 GOSUB 1000        : REM JUMP TO SUBROUTINE
30 PRINT "BACK IN MAIN"
40 END
1000 REM *** MY SUBROUTINE ***
1010 PRINT "INSIDE SUBROUTINE"
1020 RETURN          : REM GO BACK TO LINE 30

Practical Example: Drawing a Box

10 X=5:Y=5:W=10:H=5:GOSUB 500 : REM DRAW BOX 1
20 X=20:Y=10:W=15:H=8:GOSUB 500 : REM DRAW BOX 2
30 END
500 REM *** DRAW BOX SUBROUTINE ***
510 FOR I=0 TO W
520 POKE 1024+Y*40+X+I, 64
530 POKE 1024+(Y+H)*40+X+I, 64
540 NEXT I
550 FOR I=0 TO H
560 POKE 1024+(Y+I)*40+X, 66
570 POKE 1024+(Y+I)*40+X+W, 66
580 NEXT I
590 RETURN

Standard Subroutine Locations

Line Range Typical Use
1-999 Main program
1000-1999 Initialization routines
5000-5999 Game logic
9000-9999 Utility subroutines
Important: Every GOSUB must have a matching RETURN, or your program will crash!
This website relies on temporary cookies to function, but no personal data is ever stored in the cookies.
OK

Ladataan ...