Statement syntax

EGL statements are composed of keywords, expressions, operators, and punctuation. Most end with a semicolon. Other statements -- those which can contain other statements -- end with the keyword end. All statements can span multiple lines, and extra whitespace is insignificant, so you may format your code however you prefer.

Comments

Comments may appear anywhere in an EGL source file. EGL supports two kinds of comments:

Line comments start with the characters // and stop at the end of the current line.

Block comments start with the characters /* and stop with the characters */. Block comments can span multiple lines.

In this example, the variable x is assigned 1 and the variable y is assigned 2.

x =// This is a line comment.1;
y /* This is a block comment. It
extends
over
five
lines. */=/* This is another block comment. */2;

The previous example has the same effect as these statements:

x =1;
y =2;

General statements

Assignment

An assignment statement gives a value to a variable or an element of a list. The source of the assignment can be any expression whose type is compatible with the assignment's target. If the source and target don't have the same type, the source will be converted to the target's type, if possible.

As shown, no more than one clause ever executes. Control does not “fall through” from one clause to the next.

Continue

The continue statement returns control to the start of a block of code controlled by a for, forEach, or while statement. The statement lets you return to a labeled statement of one of those kinds, or to the nearest embedding statement of one of those kinds.

The code displays each integer on its own line, inserting a blank line after each group of three.

Declaration

New variables are created using declaration statements. A declaration consists of the name of the new variable, followed by its type.

Declarations can optionally include an initializer, which assigns an initial value to the new variable. Variables declared without an initializer have the default value for their type (zero, the empty string, false, null, etc.).

Multiple variables of the same type can be declared in a single statement. Simply put a comma between each variable's name. If a declaration of multiple variables has an initializer, all of the variables are assigned the same initial value.

name string;// Declares a variable called 'name' of type string.
row, column int;// Declares two ints.
defaultName string ="Action";// A declaration with an initializer.
defaultRow, defaultColumn int=10;// Declares and initializes two ints.

Exit

The exit statement exits from a function, program, service, or run unit; or from a block of code controlled by a case, for, forEach, if, or while statement.

For

The for statement runs a set of statements in a loop that repeats until a counter exceeds a specified value.

The example code shows three variations of a for statement that adds the same set of numbers.

program MyTestProgram
function main()
inputList int[]=[10, 4, 6, 8, 2];
numberInList int= inputList.getSize();
sum =0;// the first for loop increments by 1.for(i int from 1 to numberInList)
sum = inputList[i]+ sum;
end
SysLib.writeStdOut("sum after the first for loop is "+ sum);
sum =0;// the second for loop has the same effect but specifies the increment value. for(i int from 1 to numberInList by 1)
sum = inputList[i]+ sum;
end
SysLib.writeStdOut("sum after the second for loop is "+ sum);
sum =0;// the third for loop starts at the opposite side of the list and decrements by 1for(i int from numberInList to 1 decrement by 1)
sum = inputList[i]+ sum;
end
SysLib.writeStdOut("sum after the third for loop is "+ sum);
end
end

In each case, the variable i was local to the for statement. Here is an alternative:

i int;for(i from 1 to numberInList)
sum = inputList[i]+ sum;
end

After that code ends, the value of i is available and equals numberInList + 1.

Function invocation

This kind of statement invokes a function. If the function invoked this way returns a value, that value is ignored.

This is "hello world" in EGL. The single statement in the program passes the string "Hello world!" to the function SysLib.writeStdout.

program HelloWorld
function main()
SysLib.writeStdout("Hello world!");
end
end

Function invocations are also a kind of expression, so they can appear in many other places, such as the source of an assignment, or as an argument to another function invocation.

A variable of the delegate type RunFunction may be used refer to functions by name and to invoke these functions. A function referred to by a variable of type RunFunction must accept no parameters and return no values. (This is somewhat akin to a function pointer in some other languages.)

If

The if statement runs a set of statements if a logical expression resolves to true. The optional else keyword marks the start of an alternative set of statements that run only if the logical expression resolves to false.

The following code shows how to embed If statements in other If statements.

Return

Throw

Try

The try statement lets you handle errors. It contains a block of code, followed by one or more onException blocks. Each onException block allows you to deal with a particular type of Exception, should it be thrown by the statements in the body of the try.

The statements within the try statement are executed, until the last one finishes or an Exception is thrown. If an Exception is thrown, and the try statement has an onException block for that type of Exception, control jumps to that onException block. The Exception that was thrown is available as a local variable in the onException block.

An onException block for the type AnyException will "catch" every Exception that's not handled by any other onException block of the try statement.

If an Exception is thrown within the body of a try statement, and it has no onException block for AnyException or the type of Exception that was thrown, then the try statement doesn't handle that Exception.

Close

Delete

Execute

ForEach

Get

This example shows how to create a select statement using multiple substitution variables for the where-clause.
The substitution variables dateYYYYMMDD and timeHHMMSS are of type int. Example values are "20100415" and "120120" respectively, sans quotes.