・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.
@MAINLOOP
Jump destination label
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.
GOTO @MAIN JP$="@MAIN":GOTO JP$
・Unlike GOTO, the RETURN command returns to the next command of GOSUB.
Jump destination label
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.
GOSUB @SUB JP$="@MAIN":GOSUB JP$
RETURN
The jump destination is selected according to the value of the expression written here.
・The value must be numeric.
Jump destination when the value of the expression is 0
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.
ON IDX GOTO @JMP_A,@JMP_B PRINT OVER:END @JMP_A PRINT "IDX=0":END @JMP_B PRINT "IDX=1":END
The jump destination is selected according to the value of the expression written here.
The value must be numeric.
Jump destination when the value of the expression is 0
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.
ON IDX GOSUB @SUB_A,@SUB_B PRINT EXIT:END @SUB_A PRINT "IDX=0":RETURN @SUB_B PRINT "IDX=1":RETURN
・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.
Jump destination when program stops
ON BREAK GOTO @FINISH LOOP ENDLOOP @FINISH PRINT "Stopped!"
If there is ELSE, execute CodeBlock2 when false (0)
・It's possible to not specify GOTO right after THEN and ELSE.
IF A==1 THEN PRINT OK IF A>1 THEN @JMP1 ELSE PRINT DATE$ @JMP1 END
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.
IF A==1 THEN PRINT "Congratulations" BEEP 2 ELSE PRINT "Too bad" ENDIF
・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.
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
・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"
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
・Terminate branch operation with ENDCASE.
・Branch conditions are specified by WHEN and OTHERWISE.
Expression referenced as a condition in CASE
・Used for comparison with the expression specified by WHEN.
A=1 CASE A WHEN 0: PRINT"A" WHEN 1: PRINT"B" OTHERWISE: PRINT"X" 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.
Expression that becomes a branch condition
・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 must be used after conditional branch is started with CASE.
・This command itself does nothing.
・When executing the ENDLOOP command, it jumps to the command immediately following the corresponding LOOP keyword.
I=0 LOOP PRINT I;","; I=I+1 IF I>100 THEN BREAK ENDLOOP
・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.
I=0 LOOP PRINT I;","; I=I+1 IF I>100 THEN BREAK ENDLOOP
・Place a NEXT command at the end of the process.
・If the condition is not met, it may not be executed even once.
Variable that is automatically updated on every loop
・Increment is added for each loop.
The value of the loop variable at the start of the loop
The value of the loop variable that terminates the loop
・When the value of the loop variable exceeds this value, the loop is terminated.
・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.
FOR I=0 TO 9 STEP 2 PRINT I;","; NEXT
・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.
FOR I=0 TO 9 STEP 2 PRINT I;","; NEXT
・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.
A=0:B=4 WHILE A<B A=A+1 WEND
A=0:B=4 WHILE A<B A=A+1 WEND
・This command itself does nothing.
・When loop execution is continued with the UNTIL command, it jumps to the corresponding REPEAT command.
A=0:B=4 REPEAT A=A+1 UNTIL A>B
・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.
A=0:B=4 REPEAT A=A+1 UNTIL A>B
・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.
FOR I=0 TO 9 IF I==1 THEN CONTINUE IF I==7 THEN BREAK PRINT I;","; NEXT
・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.
FOR I=0 TO 9 IF I==1 THEN CONTINUE IF I==7 THEN BREAK PRINT I;","; NEXT
END
・Interrupted program slot: The line number is displayed.
・A program interrupted by STOP can be continued with the CONT command.
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.
STOP STOP "Stopped"
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)
・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.
' Display characters DEF FUNC PRINT "SAMPLE" END ' Call FUNC
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.
' Display characters at the specified position DEF FUNC2 X,Y LOCATE X,Y PRINT "SAMPLE" END ' Call FUNC2 10,4
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.
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)
'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")
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.
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.
' 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
・It is possible to make only the parameter variable-length, or make the return value variable-length.
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.
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.
DEF VARFUNC * OUT * FOR I=0 TO DEFOUTC()-1 DEFOUT I, DEFARG(I)*2 NEXT END
・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
COMMON DEF FOO(X,Y,Z)
・Used when returning a value in a DEF command defined as a function type.
DEF CALC(A,B) RETURN A*B END PRINT CALC(2,3)
DEF FUNC PRINT FUNC END
・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length parameters.
The number of parameters of a user-defined command/function
DEF FOO X,Y PRINT DEFARGC() END
・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length parameters.
Number of parameter to check
・Specify 0,1,2,3 ... sequentially from the first parameter.
The value of the specified parameter
DEF FOO X, Y PRINT DEFARG(0) 'Returns X value PRINT DEFARG(1) 'Returns Y value END
・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length return value.
Number of return values of a user-defined command/function
DEF FOO OUT X,Y PRINT DEFOUTC() END
・It can be used only within user-defined commands and functions.
・Convenient when combined with variable-length return value.
Return number to be specified
・Specify 0,1,2,3 ... sequentially from the first return value.
Value to be set in the specified return value
DEF FOO OUT X,Y DEFOUT 0,10 'Same meaning as X=10 DEFOUT 1,20 'Same meaning as Y=20 END
・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.
Parameters required for the specified commands
Describe as many variable names as you want to return as a result after OUT
CALL "USERCD",X,Y OUT A,B ' DEF USERCD X,Y OUT A,B A=X+Y:B=X*Y END
・Both built-in functions and user-defined functions can be specified.
・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.
Enumerate parameters required for specified function
The value returned by the specified function
A=CALL("USERFC",X,Y) ' DEF USERFC(X,Y) RETURN X*Y END
・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().
CALL SPRITE CALL TEXT