Control Structures

IF {condition}
	{program code}
[ELSE IF {condition}]
[ELSE]
	{program code}
END [IF]


WHILE {condition}
	[BREAK]
	[LOOP]
	{program code}
END [WHILE]


FOR {long variable}={expression} to {expression} [step {expression}]
	[BREAK]
	[LOOP]
	{program code}
NEXT


SWITCH {expression}
CASE {constant}
	[BREAK]
[DEFAULT]
END [SWITCH]


BLOCK {variable} [WITH {variable}]
    [BREAK]
    [LOOP]
	{program code}
END [BLOCK]


TEXT {variable}
	{text}
    [<<variable>>]
END [TEXT]

ON ERROR [RETURN | DO {procedure name}]

DO {procedure name}

PROC {procedure name}
    [EXIT]
END [PROC]

MACRO method() | method('some character constant')

RETURN [{expression}]
Note: [] means optional
{condition}- calculates to either _TRUE or _FALSE. It can be composed of any combination of the following.
Type Example
Logical constant _TRUE, _FALSE
Comparison a>c
Logical operation a>c and not c<=d
Expression a-b*myapp.total > 500
Conditions <, <=, >, >=, <>, =
Logicals and, or, not

{expression}- any combination of variables, constants and operators. Precedence is from left to right unless a set of "( )" is used. Anything in the round brackets is executed first.

Type Operators Examples
Numerical +, -, *, / a+(b*c)+10
Character + myapp.hello + "This is the last day"
Logical and, or, not is_true or _TRUE
Date +, - mdate + 20
Class, Object, Index and Table variables cannot use operators. Only the assignment (=) can be used and no conversions are done. (Object=Object, Class=Class, and Index=Index only Note: The right side of the expression can be a function that returns a Class, Index etc)

{constant}- Any numeric, or character constant e.g. 5, 10.87, 'A', 'string'
{long variable}- In the case of the FOR command above, {variable} is always a Long (4 byte) integer.
{variable}- Any of the variable types including any type of Object.
{vector variable}- Any variable type that has multiple members like a[5], b[2,3] Note: 1 to 2 dimensions only.
{program code}- Any combination of "Program Structures" and the assignment command ("="). e.g. data=15 + i*b
{text}- Any text data but the end is defined as [{white space}] END (case doesn't matter) on a new line.
{method}- A program associated with an Object, defined in a Class. e.g. myclass.mymethod() : the round brackets are required to specify a method.
{<< variable >>}- Text or numbers (converted to char automatically) can be inserted into the text by using a << variable >> in the text structure.

4.1 IF ELSE END ELSE IF

4.2 WHILE BREAK LOOP END

4.3 FOR BREAK LOOP NEXT

// Example

long a[100]             // create 100 elements and initialize to 0

b=0
for i=1 to a.length()
    b=b+a[i]            // add all 100 numbers of "a" vector
next

4.4 SWITCH, CASE, BREAK, DEFAULT END

4.5 BLOCK BREAK LOOP END
// Examples

class myclass {
	char name(30)
	char custn(6)
	number balance(10,2)
}xcust(this, 100), cust(myclass, 1000)   // define a class and create 2 tables
                                         // this and myclass are the same class in the above line
=cust.import('test.txt','text')          // import test data : cust is buffered in 1000's of records but can be any size
block cust                               // buffer and loop through cust
    if cust.state='ND'                   // each time through the block structure the default object is filled with each record of cust
        xcust.append(cust)               // append all matching fields from default object of cust to xcust if state='ND' for current record
    endif
endb

total=0.00                     // create a double float variable : double constant is created if a decimal is used otherwise a 4 byte integer would be created
block xcust                    // buffer and loop through xcust
    ? xcust.name               //  display name field
    total=total+xcust.balance  // sum total of balance field for all records from state='ND'
endb

long a[2,5]
block a with g
    ? g   // this would display 10 numbers in row wise order : left to right
endb

long a[2,3],b
b=0
block a with g
    b=b+g   // this puts the sum of all elements of a in b
endb

4.6 TEXT <<variable>> END

4.7 ON ERROR DO

4.8 DO

4.9 PROC EXIT END

4.10 MACRO

4.11 RETURN

4.12 SQL

4.13 CLASS APP INHERIT

4.14 REGISTER END

4.15 ? ?? CURSOR CLEAR SCREEN