User Tools


reference:control_commands

Control Commands

@Label

Identifier indicating the location of the program or data

・Define the jump destination specified by GOTO and GOSUB commands and the read destination of the READ command specified by the RESTORE command.
・The label is an identifier consisting of alphanumeric characters and underscore (_) with @ at the beginning.

Example

@MAINLOOP

GOTO @Label
GOTO String

Jump to the specified label position

Arguments

@Label

Jump destination label

String

You can also specify a string with a label name instead of a label.

・Program slot specification is possible in the format of "1:@LabelName".
・When specifying a program slot, make sure that the program in the target slot executable with the EXEC command in advance.

Example

GOTO @MAIN
JP$="@MAIN":GOTO JP$

GOSUB @Label
GOSUB String

Jump to the specified label position

・Unlike GOTO, the RETURN command returns to the next command of GOSUB.

Arguments

@Label

Jump destination label

String

You can also specify a string with a label name instead of a label.

・Program slot specification is possible in the format of "1:@LabelName".
・When specifying a program slot, make sure that the program in the target slot executable with the EXEC command in advance.

Example

GOSUB @SUB
JP$="@MAIN":GOSUB JP$

RETURN

Jump to the command following the GOSUB command used immediately before.

Example

RETURN

ON Expression GOTO @Label0,@Label1…

Branch to the label line corresponding to the value of the expression

Arguments

Expression

The jump destination is selected according to the value of the expression written here.

・The value must be numeric.

@Label0

Jump destination when the value of the expression is 0

@Label1

Jump destination when the value of the expression is 1

・Prepare as many destinations as you need.
・Strings cannot be used for the ON to GOTO labels.

Example

ON IDX GOTO @JMP_A,@JMP_B
PRINT OVER:END
@JMP_A
PRINT "IDX=0":END
@JMP_B
PRINT "IDX=1":END

ON Expression GOSUB @Label0,@Label1…

Branch to the label line corresponding to the value of the expression and return to the next command after ON GOSUB by using the RETURN command

Arguments

Expression

The jump destination is selected according to the value of the expression written here.

The value must be numeric.

@Label0

Jump destination when the value of the expression is 0

@Label1

Jump destination when the value of the expression is 1
:
・Prepare as many destinations as you need.
・Strings cannot be used for the ON to GOSUB labels.

Example

ON IDX GOSUB @SUB_A,@SUB_B
PRINT EXIT:END
@SUB_A
PRINT "IDX=0":RETURN
@SUB_B
PRINT "IDX=1":RETURN

ON BREAK GOTO @Label

Register the jump destination when the user tries to stop the program

・If you press the + Button during program execution, the program will normally stop. But, you use ON BREAK GOTO to jump to the specified label.
・Once you jump to the registered label, the registration is canceled.
・If the program stops due to an error, TRACE,STOP execution, forced stop by pressing + Button, programs start from the Top Menu, etc., it will not jump even if a label is registered.

Argument

@Label

Jump destination when program stops

Example

ON BREAK GOTO @FINISH
LOOP
ENDLOOP

@FINISH
PRINT "Stopped!" 

IF Expression THEN CodeBlock1
IF Expression THEN CodeBlock1 ELSE CodeBlock2

CodeBlock1 is executed when the value of the expression is true (other than 0)

If there is ELSE, execute CodeBlock2 when false (0)

・It's possible to not specify GOTO right after THEN and ELSE.

Example

IF A==1 THEN PRINT OK
IF A>1 THEN @JMP1 ELSE PRINT DATE$
@JMP1
END

IF Expression THEN [LineFeed] CodeBlock1 ENDIF
IF Expression THEN [LineFeed] CodeBlock1 ELSE [LineFeed] CodeBlock2 ENDIF

CodeBlock1 is executed when the value of the expression is true (other than 0)

If there is ELSE, execute CodeBlock2 when false (0)

・If a line feed occurs immediately after THEN or ELSE, multiple lines can be written in CodeBlock1 or CodeBlock2.
・When a line feed occurs immediately after THEN or ELSE, describe ENDIF at the end to clearly display the end of the IF statement.

Example

IF A==1 THEN
 PRINT "Congratulations" 
 BEEP 2
ELSE
 PRINT "Too bad" 
ENDIF

ELSEIF Expression THEN ...

Keywords for executing additional IF statements when conditions are not satisfied by IF statements

・By using ELSEIF instead of ELSE, it is possible to make a condition judgment after the condition is not satisfied.
・Note that the contents of the following code description change between ELSEIF and ELSE IF. The two codes in the example have the same meaning.

Example

IF A==1 THEN
 PRINT "Congratulations":BEEP 0
ELSEIF A==2 THEN 
 PRINT "Too bad" 
ELSE
 PRINT "So-so" 
ENDIF

IF A==1 THEN
 PRINT "Congratulations":BEEP 0
ELSE
 IF A==2 THEN 
  PRINT "Too bad" 
 ELSE
  PRINT "So-so" 
 ENDIF ' Required for ELSE IF
ENDIF

IF Expression GOTO @Label [ELSE CodeBlock]

Branch to label when expression is true (other than 0)

Notes on using character strings for labels

・Label strings can also be used for labels.
・Strings cannot be used when GOTO is not specified immediately after ELSE.

Bad) IF A==0 GOTO "@LABEL1" ELSE "@LABEL2"
Good) IF A==0 GOTO "@LABEL1" ELSE @LABEL2
Good) IF A==0 GOTO "@LABEL1" ELSE GOTO "@LABEL2"

Example

IF A==1 GOTO @MAIN
IF X<0 GOTO @JMP1 ELSE PRINT A$
IF Y==5 GOTO @JMP1 ELSE @JMP2
@JMP1
PRINT "@JMP1" 
@JMP2
PRINT "@JMP2" 
END

CASE Expression

Start conditional branch by CASE

・Terminate branch operation with ENDCASE.
・Branch conditions are specified by WHEN and OTHERWISE.

Argument

Expression

Expression referenced as a condition in CASE

・Used for comparison with the expression specified by WHEN.

Example

A=1
CASE A
WHEN 0: PRINT"A" 
WHEN 1: PRINT"B" 
OTHERWISE: PRINT"X" 
ENDCASE

WHEN Expression

Specify the branch condition in CASE to ENDCASE

・If the value of the expression specified by WHEN and the value of the expression specified by CASE are the same, jump to the next command after WHEN, and jump to the next WHEN or OTHERWISE if the values are different.
・When jumping to the next command to WHEN, jumps to ENDCASE when executed until just before the next WHEN.
・When WHEN is written continuously, it is treated as a group.
・In other words, when WHEN A:WHEN B is written, it means "when CASE value is A or B".
・It can only be used within CASE to ENDCASE.

Argument

Expression

Expression that becomes a branch condition

OTHERWISE

Specify what to do when none of the WHENs is correspond within CASE to ENDCASE

・If all WHEN is not correspond, jump to the next command of OTHERWISE.
・Process equivalent to ELSE in IF statement.
・WHEN cannot be used after OTHERWISE.

ENDCASE

Terminate conditional branch by CASE

・ENDCASE must be used after conditional branch is started with CASE.

LOOP

LOOP to ENDLOOP loop start keyword

・This command itself does nothing.
・When executing the ENDLOOP command, it jumps to the command immediately following the corresponding LOOP keyword.

Example

I=0
LOOP
 PRINT I;",";
 I=I+1
 IF I>100 THEN BREAK
ENDLOOP

ENDLOOP

Jump to the command immediately following the corresponding LOOP keyword

・Unlike other loop commands such as FOR, WHILE, and REPEAT, it continues to loop indefinitely.
・To break out of the loop, you need to use the BREAK command.

Example

I=0
LOOP
 PRINT I;",";
 I=I+1
 IF I>100 THEN BREAK
ENDLOOP

FOR LoopVariable=InitialValue TO EndValue
FOR LoopVariable=InitialValue TO EndValue STEP Increment

Repeat the process a specified number of times

・Place a NEXT command at the end of the process.
・If the condition is not met, it may not be executed even once.

Arguments

LoopVariable

Variable that is automatically updated on every loop

・Increment is added for each loop.

InitialValue

The value of the loop variable at the start of the loop

TO EndValue

The value of the loop variable that terminates the loop

・When the value of the loop variable exceeds this value, the loop is terminated.

STEP Increment

・An increment to add to the loop variable at the end of the loop.
・If not specified, 1 is used as the increment value.
・If a negative number is specified, the value can be looped in a decreasing direction.
・If the increment is a decimal, it may not be the intended number of times due to calculation error.

Example

FOR I=0 TO 9 STEP 2
 PRINT I;",";
NEXT

NEXT

Command indicating the end of a FOR loop

・Updates the corresponding FOR variable, jumps to the command immediately after FOR if it does not exceed the value of TO, and jumps to the command immediately after NEXT if it exceeds.
・If the FOR variable has STEP, add the value of STEP, and if there is no STEP, add 1.

Example

FOR I=0 TO 9 STEP 2
 PRINT I;",";
NEXT

WHILE Expression

If the calculation result of the expression is false (0), jumps to the command following the next WEND.

・If the expression is true (other than 0), jump to the next command after WHILE, and return to WHILE when the WEND command comes and calculate the expression again.

Example

A=0:B=4
WHILE A<B
 A=A+1
WEND

WEND

Jump to the previous WHILE command and execute again from WHILE.

Example

A=0:B=4
WHILE A<B
 A=A+1
WEND

REPEAT

REPEAT-UNTIL loop start command

・This command itself does nothing.
・When loop execution is continued with the UNTIL command, it jumps to the corresponding REPEAT command.

Example

A=0:B=4
REPEAT
 A=A+1
UNTIL A>B

UNTIL Expression

If the expression evaluates to false (0), jumps to the corresponding REPEAT command.

・If the evaluation result of the expression is true (other than 0), the loop is terminated and jumps to the next command after the UNTIL statement.
・Place a REPEAT command at the beginning of the loop.
・Unlike the WHILE command, the condition is judged after executing the in-loop code.

Example

A=0:B=4
REPEAT
 A=A+1
UNTIL A>B

CONTINUE

Force the next loop to start

・It can be used in LOOP-ENDLOOP, FOR-NEXT, WHILE-WEND, REPEAT-UNTIL.
・In a LOOP statement, jumps to LOOP when CONTINUE is executed.
・In the FOR statement, when CONTINUE is executed, the program jumps to FOR and the loop variable is updated.
・In the WHILE statement, jumps to WHILE when CONTINUE is executed.
・In the REPEAT statement, jumps to UNTIL when CONTINUE is executed.

Example

FOR I=0 TO 9
 IF I==1 THEN CONTINUE
 IF I==7 THEN BREAK
 PRINT I;",";
NEXT

BREAK

Escape the loop forcibly

・It can be used in LOOP-ENDLOOP, FOR-NEXT, WHILE-WEND, REPEAT-UNTIL.
・When BREAK is used, it jumps to the command immediately after the loop in all loop statements.

Example

FOR I=0 TO 9
 IF I==1 THEN CONTINUE
 IF I==7 THEN BREAK
 PRINT I;",";
NEXT

END

Quit the program

Example

END

STOP [DisplayString]

Suspending a running program

・Interrupted program slot: The line number is displayed.
・A program interrupted by STOP can be continued with the CONT command.

Argument

DisplayString

Specify a string to be displayed as a stop message

・Strings can be displayed up to 255 characters.
・If not specified, the stop message will not be displayed.

Example

STOP
STOP "Stopped" 

About DEF User-Defined Commands

Using DEF, you can define your own commands like the below

1) USER (no argument, no return value)
2) USER X,Y (with arguments, no return value)
3) A=USER(X) (with arguments, 1 return value)
4) USER X OUT A,B (with arguments, multiple return values)

DEF Common Rules

・The definition range is from DEF to END.
・Defined variables and labels in the DEF to END range cannot be used from outside the DEF (local variables).
・GOTO and GOSUB across the DEF to END range are not possible.
・By adding COMMON, you can define commands that can be used from outside the defined program slot.

DEF DefinitionName

Define a user-defined command with no arguments and no return value

Example

' Display characters
DEF FUNC
PRINT "SAMPLE" 
END
' Call
FUNC

DEF DefinitionName Parameter[,Parameter...]

Define a user-defined command with parameters and no return value

Parameter

If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.

・The parameter name specified here can be used as a variable in DEF-END.

Example

' Display characters at the specified position
DEF FUNC2 X,Y
LOCATE X,Y
PRINT "SAMPLE" 
END
' Call
FUNC2 10,4

DEF FunctionName([Parameter[,Parameter...]])

Define a user-defined function (user-defined command with only one return value)

Parameter

If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.

・The parameter name specified here can be used as a variable in DEF-END.

Return Value

When you want a value to return to the caller as a result, specify it as using the RETURN command in DEF-END. (description like RETURN ANS)

Example

'Addition
DEF ADD(X,Y)
RETURN X+Y
END

' Factorial calculation using recursion
DEF FACTORIAL(N)
IF N==1 THEN RETURN N
RETURN N*FACTORIAL(N-1)
END

' String inversion
DEF REVERSE$(T$)
VAR A$="" 'Local string
VAR L=LEN(T$) 'Local
WHILE L>0
 A$=A$+MID$(T$,L-1,1)
 DEC L
WEND
RETURN A$
END

' Call
PRINT ADD(10,5)
PRINT FACTORIAL(4)
PRINT REVERSE$("BASIC")

DEF CommandName[Parameter[,Parameter...]] OUT ReturnValue [,ReturnValue...]]

Define a user-defined command with multiple return values

Parameter

If there are parameters that you want to pass to the function, specify the required parameter names separated by commas.

・The parameter name specified here can be used as a variable in DEF-END.

Return Value

Describe as many variable names as you want to return as a result after OUT

・By storing a value to the variable specified here in DEF-END, the value can be returned to the caller.

Example

' Addition and multiplication
DEF CALCPM A,B OUT OP,OM
OP=A+B
OM=A*B
END

' Call
CALCPM 5,10 OUT P,M
PRINT P,M

DEF CommandName * [OUT *]

Define a user-defined command with variable-length parameters and variable-length return values

・It is possible to make only the parameter variable-length, or make the return value variable-length.

Parameter

You can declare that the number of parameters is variable-length by writing * (asterisk) after the command name.

・Use DEFARGC, DEFARG, TYPEOF to investigate the number, content, and type of parameters.

Return Value

Write * (asterisk) after OUT to declare that the number of return values is variable-length.

・You can use DEFOUTC and DEFOUT to investigate the number of return values and set the return value.

Example

DEF VARFUNC * OUT *
 FOR I=0 TO DEFOUTC()-1
  DEFOUT I, DEFARG(I)*2
 NEXT
END

About COMMON

A keyword used to define a user-defined command/function beyond the program slot

・When using a program between different program slots, execute it with EXEC first.

1) COMMON DEF USER
2) COMMON DEF USER(X)
3) COMMON DEF USER X OUT A,B

Example

COMMON DEF FOO(X,Y,Z)

RETURN Value

Set the return value of DEF and return to the caller

・Used when returning a value in a DEF command defined as a function type.

Example

DEF CALC(A,B)
 RETURN A*B
END
PRINT CALC(2,3)

END

Terminate DEF definition of a user-defined command/function

Example

DEF FUNC
 PRINT FUNC
END

DEFARGC()

Check the number of parameters of a user-defined command/function

・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length parameters.

Return Value

The number of parameters of a user-defined command/function

Example

DEF FOO X,Y
PRINT DEFARGC()
END

DEFARG(ParameterNumber)

Check the value of parameters of a user-defined command/function

・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length parameters.

Argument

ParameterNumber

Number of parameter to check

・Specify 0,1,2,3 ... sequentially from the first parameter.

Return Value

The value of the specified parameter

Example

DEF FOO X, Y
PRINT DEFARG(0) 'Returns X value
PRINT DEFARG(1) 'Returns Y value
END

DEFOUTC()

Check the number of return values of a user-defined command/function

・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length return value.

Return Value

Number of return values of a user-defined command/function

Example

DEF FOO OUT X,Y
PRINT DEFOUTC()
END

DEFOUT ReturnValueNumber,Value

Specify the return value of a user-defined command/function

・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length return value.

Parameters

ReturnValueNumber

Return number to be specified

・Specify 0,1,2,3 ... sequentially from the first return value.

Value

Value to be set in the specified return value

Example

DEF FOO OUT X,Y
DEFOUT 0,10 'Same meaning as X=10
DEFOUT 1,20 'Same meaning as Y=20
END

CALL CommandName[,Parameter...][ OUT Variable1[,Variable2...]]

Call a user-defined command with a specified name

Parameters

CommandName

・A string of the user-defined command name to be called.
・Program slot specification is possible in the format of "1:User-DefinedCommandName".
・Make the program in the target slot executable with the EXEC command in advance.

Parameter ~

Parameters required for the specified commands

Return Value

Describe as many variable names as you want to return as a result after OUT

Example

CALL "USERCD",X,Y OUT A,B
'
DEF USERCD X,Y OUT A,B
A=X+Y:B=X*Y
END

CALL(FunctionName[,Parameter...])

Call function with specified name

・Both built-in functions and user-defined functions can be specified.

Parameters

FunctionName

・A string of the user-defined function name to be called.
・Program slot specification is possible in the format of "1:User-DefinedFunctionName".
・Make the program in the target slot executable with the EXEC command in advance.

Parameter

Enumerate parameters required for specified function

Return Value

The value returned by the specified function

Example

A=CALL("USERFC",X,Y)
'
DEF USERFC(X,Y)
RETURN X*Y
END

CALL SPRITE
CALL TEXT

Call callback

・Calls the specified callback operation by SPFUNC and TFUNC all at once.
・Specified callback with SPFUNC is called with CALL SPRITE.
・Specified callback with TFUNC is called with CALL TEXT.
・The sprite management number and text screen ID related to the called callback can be obtained with CALLIDX().

Example

CALL SPRITE
CALL TEXT

reference/control_commands.txt · Last modified: 2023/12/07 15:54 (external edit)

Page Tools