FOR
<variable> = <expression> to <expression> [step <constant>]
...
...
NEXT [<variable> (ignored)]examples:
FOR angle = 1+ASIN(0.4) to 1+ASIN(0.75) step 0.1
PRINT angle
NEXT
FOR y = 1 to 200
FOR x = 1 to 320
s = s + x*y
NEXT
NEXT
REPEAT-UNTIL instruction:
This instruction repeats a series of instructions until the condition is
True. The block begins with the REPEAT command and ends with the UNTIL
command followed by the condition that is evaluated.
Example:
a = 1
REPEAT
PRINT a
a = a+1
UNTIL a>10
The Repeat instruction evaluates the condition at the
end of the loop, this means that the instructions inside the loop are
executed at least once. The Break and Continue instructions can be used
in REPEAT-UNTIL cycles just like in the FOR-NEXT
cycles.
WHILE-ENDWHILE
instruction:
This instruction evaluates a condition at the beginning of the loop. If
the condition is false then the cycle stops and execution continues
after the Endwhile instruction.
Example:
a = 1
WHILE a <= 10
PRINT a
a = a+1
ENDWHILE
Since the While command evaluates the condition at the
beginning of the loop, the instructions inside the loop may be also
executed never. The Break and Continue instructions can be used in
WHILE-ENDWHILE cycles just like in the FOR-NEXT cycles.
Strings
A string variable contains text. This text may be a
single row or a multi-line text. The maximum theoretical size of a
string variable is 2 Gbyte.
Example:
a$ = "Hello" + "World" + "!"
The value of the variable "a$" is now "HelloWorld!"
String variables are used with operators to perform string expressions
and are used with some functions to Open and Save data from text files.
A single row of a multi-line string con be read using square brackets,
example:
if a$ contains:
" This is a
text placed on
three rows "
b$ = a$[2]
Now b$ contains: "text placed on"
Numbers
A numeric variable contains a number. The number is
internally represented by a floating point value with double precision
(64 bit, 15 significant digits).
Numeric variables are used with
operators to perform numeric expressions and are used as counters in
loop instructions.
Jump instructions
The following instructions (Goto, Gosub, Return) are
supported only for compatibility with Basic.
They cannot be used inside Functions.
Goto instruction:
This instruction jumps at the given label.
Example:
10 if a > 5 then GOTO 30
20 print "a <= 5"
30 print "Script ended"
Gosub - Return instructions:
They were used to make subroutines. Now it's better to define a Function.
Example:
10 x = 3 : y = 6
20 GOSUB 100
30 print "Result:" ; r
40 end
100 r = sqrt(x^2+ y^2)
110 RETURN
Basic functions
A function is defined as set of
instructions that computes and returns a value.
The result can be discarded (like
C and Delphi) or simply not returned, making it a procedure. Local
variables can be defined to support recursive functions.
Syntax:
Function <Name> ( parameters ) [ Local <local variables> ]
...
[Return <result>]
...
Endfunc
Examples:
FUNCTION sum(a,b)
return a+b
ENDFUNC
FUNCTION intpower(a,b) LOCAL t,r
r=1
for t = 1 to b
r = r * a
next
return r
ENDFUNC
FUNCTION hello$(a$)
return "Hello to you " + a$
ENDFUNC
Basic fully supports recursive functions, example:
FUNCTION factorial(n)
if n <= 1 then return 1
return n*factorial(n-1)
ENDFUNC
Conditional instructions
The IF-THEN instruction evaluates a logical expression
and determines the flow of the program based on the result of that
expression.
Examples of logical expressions:
a > 5 and b > 5
a >= 3 or not b <> 5 and b+3 = c
Precedence of operators:
Higher precedence:
< , > , <= , >= , <> , =
NOT
AND
OR
Lower precedence.
Syntax:
IF <logical expression> THEN
...
...
[ELSE]
...
...
ENDIF
Compact Syntax:
IF <logical expression> THEN <instruction> : <instruction> ...
IF instructions can be nested without limits; the ELSE
part is optional and is not allowed in the compact syntax.
Examples:
IF a < 0 and a > -10 THEN print "A was a small negative number": a = -a
IF a >= 0 THEN
print a
IF a = 12 THEN print "A prefect number !"
IF a > 1000 THEN
print "What a big number"
ENDIF
ELSE
print "Negative numbers not allowed!"
ENDIF
Identifiers
Identifiers denote variables and functions.
An identifier can be of any length, must begin with a letter and can't
contain spaces.
String identifiers denote string variables and string
functions.
The last character must be $
examples of valid identifiers:
counter , temp , pix , n , n2
name$ , address2$ , filename$ , a$
PRINT
Since there is no window to print to in Filter Script,
the print function prints to buffer that can be saved to a file.
See SavePrint function.
Print [ expression [, expression] [; expression] ]
Description:
Every expression must be separated by a semicolon or comma; if semicolon
is used then no spaces are added between the writings. If comma is used
then a TAB separator is added between the writings. Numbers are always
printed preceded by a space.
Example:
PRINT "Some math" ; 3+5 ; 4*4*4 ; sin(2.5)
INPUT Shows a dialog
window where the user can enter data.
Input [ <Question> , ] variable
Description:
Use this function to ask the user for input values.
If the user doesn't click the OK button then zero or an empty string is
returned.
Example:
INPUT "How old are you ?", a
INPUT "Your name ?", n$
PRINT n$ ; " is"; a
Operators
Operators are classified as arithmetic operators and
string operators.
Precedence:
Operators with higher precedence are performed before operators with low
precedence.
Operators with equal precedence are performed from left to right.
Numeric operators
Numeric operators apply in numeric expressions, Basic supports the
following operators:
+
-
*
/
^
?>
?<
MOD |
Addition
Subtraction
Multiplication
Division
Power
Maximum
Minimum
Modulo |
Higher precedence:
( , )
- (unary)
^
* , / , MOD
+ , - , ?> , ?<
Lower precedence.
Examples:
12 + 15 = 27
12 - 4 = 8
2 ^ 8 = 256
7 * 5 = 35
10 / 4 = 2.5
18 MOD 8 = 2
5 ?> 3 = 5
8 ?< 2 = 2
String operators
String operators apply in string expressions, Basic
supports the following operators:
+ Addition
/ Addition with New Line
- Deletion
Precedence:
String operators have the same precedence and are evaluated from left to
right.
Examples:
"Hello" + "World" = "HelloWorld"
"Hello" - 2 = "Hel"
"Hello" / "World" =
"Hello
World"