Basic features & fundamentals – Xylem System 5000 BASIC Manual User Manual
Page 8

BASIC FEATURES & FUNDAMENTALS
Basic 5000 supports traditional control statements such as GOTO and GOSUB as well as single
and multi-line IF-THEN statements and SWITCH-CASE statements. GOTO and GOSUB can
jump to labels or line numbers within the code. Line numbers may be used in the Basic program,
but they are not required.
Loops are also allowed using FOR, WHILE, REPEAT, and DO statements. BREAK statements
may be used to leave any of the previously mentioned loops while the CONTINUE command can
be used to begin the next iteration of a loop.
Control Statements and Loops
6
In order to ease the structure and flow of a Basic program, subroutines may be declared and used
to perform various operations. The separation of these subroutines allows a more procedural
approach to be taken within the code as well as simplify the reuse of segments of code in later
programs. These subroutines can accept multiple parameters, numbers or strings, and can
likewise return a number or a string, if desired. Subroutines are declared with the SUB command,
ended with the END SUB command, and return values using the RETURN command. Specific SUB
commands may also be used as special entry points for designated IO. See the
SUB command reference (1-60) for more information regarding these special cases.
REM Calculate the Volume of a Rectangle
height = 3
width = 4
depth = 5
volume = calc_volume(height, width, depth) REM sets volume to 60
SUB calc_volume(h, w, d)
vol = h * w * d
RETURN vol
END SUB
Subroutines
Basic 5000 provides a comprehensive list of math functions including logarithmic and
trigonometric functions. All trigonometric functions use radians. The following functions are
available: ABS, ACOS, ASIN, ATAN, CEIL, COS, EXP, FLOOR, FRAC, H377C, H377F, INT,
LN, LOG, MAX, MIN, MOD, RND, SGN, SIN, SQR, SQRT, TAN, XOR. Constants EULER
and PI are also available for use within Basic 5000 programs.
Math Functions
Traditional arithmetic, comparison, and logical operators are available for use within Basic and are
noted below (ordered by precedence):
Operators
Arithmetic:
^ (power)
- (unary minus)
* / % (integer modulus)
+ -
Comparison:
= ==
<><= >=
<> !=
Logical:
NOT
AND
OR