back to Table of Contents
This section provides a practical guide to writing BASIC programs on Casio pocket computers. It covers program entry, editing, execution, debugging, and the fundamental commands used in BASIC programming.
A BASIC program is a collection of numbered lines. Each line consists of a line number followed by one or more statements:
10 REM CYLINDER
20 R = 15
30 INPUT "H="; H
40 V = PI * R ^ 2 * H
50 PRINT "V="; V
60 END
100 R = 15 : A = 7 : B = 8
10 REM CYLINDER [EXE]
20 R=15 [EXE]
30 INPUT "H=";H [EXE]
40 V=PI*R^2*H [EXE]
50 PRINT "V=";V [EXE]
60 END [EXE]
A line is not stored in memory until EXE is pressed.
One-key input: Many BASIC keywords can be entered with a single key combination using SHIFT followed by the labeled key (e.g., SHIFT + INPUT key).
Before pressing EXE, use the cursor keys (left/right arrows) to move to the character you want to change, then type the correct character.
After making changes, press EXE to store the corrected line.
The LIST command displays the program. You can then scroll through it with cursor keys and make changes directly.
LIST ' Display entire program
LIST 30 ' Display from line 30
LIST 30-60 ' Display lines 30 through 60
LIST . ' Display last line executed
The EDIT command enters a line-by-line editing mode:
EDIT ' Start editing from first line
EDIT 30 ' Start editing from line 30
EDIT . ' Edit last line executed
In EDIT mode:
40 [EXE]DELETE 40-60 [EXE]NEW [EXE]NEW ALL [EXE]Two ways to execute a program:
RUN and press EXE. The program in the current program area executes.
RUN 100 starts execution from line 100.When a PRINT statement executes, STOP appears on the display and execution pauses. Press EXE to continue. To suppress the pause, end the PRINT statement with a semicolon:
10 PRINT "BASIC "; ' No pause — next output appears immediately after
20 PRINT "PROGRAM"
CONT to resume.140 REM Square root and cube root calculation
REM lines are ignored during execution. Use them to document your program. A single quote (') can substitute for REM: 140 ' Square root calculation
30 INPUT "Height="; H
INPUT displays a prompt and waits for keyboard input. The entered value is assigned to the variable.
50 PRINT "Volume="; V
PRINT displays values and strings on the screen. Separate items with ; for continuous output or , for paused output.
40 IF N > 5 THEN N = 5
50 IF N = 0 THEN GOTO 130
60 IF A > 100 THEN PRINT "Big" ELSE PRINT "Small"
IF~THEN~ELSE tests a condition. If true, the THEN clause executes. If false and ELSE is present, the ELSE clause executes. You can jump to other program areas: IF A = 1 THEN GOTO #2
120 GOTO 10
GOTO jumps to the specified line number. Can also jump to other program areas: GOTO #3
60 FOR I = 1 TO 10
70 X = X + A(I)
80 NEXT I
FOR~NEXT repeats the enclosed statements. An optional STEP value can be specified: FOR I = 10 TO 0 STEP -1
70 READ X
180 DATA 9, 7, 20, 28, 36
20 RESTORE
READ assigns values from DATA statements to variables. RESTORE resets the read pointer back to the first DATA item (or to a specific line).
100 GOSUB 1000
...
1000 REM Subroutine
1010 Y = SQR(S)
1020 RETURN
GOSUB jumps to a subroutine; RETURN returns to the statement following the GOSUB call. Can also call subroutines in other program areas: GOSUB #3
130 END
END terminates program execution. A program ends naturally when it reaches the last line, but END can terminate execution from anywhere.
15, 3.14, -27&HFF, &H1A3C (see &H)1.5E10 (1.5 × 10¹⁰)"Hello", "H="10 PRINT "TEST is valid+: "AD" + "1990" produces "AD1990"| Type | Example | Description |
|---|---|---|
| Numeric variable | A, TOTAL, x1 |
Stores a numeric value |
| String variable | A$, NAME$ |
Stores a character string |
| Numeric array | A(10), M(3,3) |
Array of numeric values |
| String array | A$(10), NAMES$(5) |
Array of character strings |
A and a are different variables.TRON enables trace mode. When a program runs, the program area and line number of each statement are displayed, and execution pauses until EXE is pressed. This lets you step through the program to find logic errors.
TRON ' Enable trace mode
RUN ' Run with tracing
TROFF ' Disable trace mode
When an error occurs, a message like SN error P0--10 is displayed, indicating:
Use LIST . or EDIT . to jump directly to the line that caused the error. See Error Messages for the full list.
After fixing an error, use CONT to resume execution from where it stopped (only works after STOP or BRK — not after an error).
Programs are preserved in memory by the backup battery even when the computer is powered off. For permanent storage, programs can be saved to external media.
SAVE "MYPROG" ' Save current program area to cassette
SAVE ALL "ALLPROGS" ' Save all program areas
LOAD "MYPROG" ' Load a program from cassette
LOAD ALL "ALLPROGS" ' Load all program areas
VERIFY "MYPROG" ' Verify saved program matches memory
SAVE "0:MYPROG.BAS" ' Save to floppy disk
LOAD "0:MYPROG.BAS" ' Load from floppy disk
SAVE "COM0:...", A ' Save as ASCII over RS-232C
FILES ' List files on floppy disk
KILL "0:OLDPROG.BAS" ' Delete a file
NAME "0:OLD" AS "0:NEW" ' Rename a file
See the individual command pages for SAVE, LOAD, FILES, KILL, and NAME for complete details on file descriptors and options.
Programs can handle errors gracefully using ON ERROR GOTO:
10 ON ERROR GOTO 100
20 INPUT "Number: "; N
30 PRINT 1 / N
40 END
100 PRINT "Error"; ERR; "at line"; ERL
110 RESUME NEXT
3355B)| Element | Bytes |
|---|---|
| Line number | 2 bytes (regardless of number size) |
| Command/keyword | 2 bytes (stored as token) |
| Each character (letters, digits, spaces) | 1 byte |
| End of line (EXE) | 1 byte |
| Overhead per line | 1 byte |
Example: 10 A = SIN X uses 2 + 1 + 1 + 1 + 2 + 1 + 1 + 1 + 1 = 11 bytes.
One of the unique features of Casio JIS BASIC is the ability to call between program areas:
GOTO #3 ' Jump to the first line of program area 3
GOSUB #5 ' Call program area 5 as a subroutine
RETURN #0 ' Return to program area 0
IF A=1 THEN #2 ' Conditional jump to program area 2
ON A GOTO #1,#2 ' Computed jump across program areas
Remember that variables are global across all program areas — a value set in P0 is visible in P3. This enables cooperation between programs but requires care to avoid naming conflicts.