General EQWatcher Concepts > Venturing into the Unknown  > Statements


Statements describe algorithmic actions that can be executed.  There are several types of statements:

Assignment statement

Assignment statements replace the current value of a variable with a new value specified by an expression. The expression must be compatible with the type of the variable.  These statements generally appear like this:

variable=expression;

Where expression is a mathematical expression manipulating the variable, which may include function calls that return values.  The variable for this type of assignment can be any type, as long as the expression results in the same data type.  For example, variable=2*3+variable+anothervariable*7;

Order of operation is: ^*/-+ in that order.  ^ in this language is for calculating powers, where in other languages it might be used for XOR.

Also available as shortcuts for "variable=variable+1" and "variable=variable-1" are:

variable++;

variable--;

Though this in C/C++ makes the variable increment (or decrement for --) itself AFTER the current statement is complete, this language requires they be used on their own line, and may not be used in an expression.  They return no value to be used, to avoid C/C++ programmers using it as if it would not be incremented right away.  This acts more like ++variable :)

If statement

The if statement generally appears like this:

if ([condition])
{
  [statements]
}

Condition understands the following operators: == (equal to, that's double equal signs), >= (greater than or equal to), >, <= (less than or equal to, <, != (not equal to).  Each side of the operator is considered an expression and will be evaluated as such.  This expression can involve function calls that return values.  These conditions only work for non-string values.  String comparison techniques are explained in another section. 

The statements are only executed "if" the condition is met.  If the condition is "1>2" then of course the statements will not be run. 

Another form of the if statement is:

if (condition)
{
  [statements]
}
else
{
  [other statements]
}

This will run much the same way, except that the other statements will only be run if the condition is NOT met.  If statements can be "nested" or placed inside each other, but each and every if and else statement MUST have its own set of brackets.

if (condition)
{
  if (condition2)
  {
    [statements]
  }
}

This causes statements to run only if BOTH conditions are met, since one is nested inside the other and will only be run if the first condition is met.

While statement

There is currently only one type of loop, in which the condition is set at the start of the loop.

while(condition)
{
  [statements]
}

This will cause EQWatcher to loop until the condition is no longer met at the start of the loop.  The condition is NOT continually checked while looping, ONLY at the beginning.  In old style BASIC terms:

10 if condition goto 40
20 rem statements
30 goto 10
40 rem end loop

That should help you understand if you are having troubles.

Please be very careful of infinite loops or extremely long loops, they may cause ugly side effects.

Break statement

The break statement is used to exit a while loop immediately.  Generally this is used when a continuing a loop is a useless waste of time or if it will cause an error.

A suggested use is as follows:

while(condition)
{
  [statements]
  if (condition2)
  {
  break;
  }
  [more statements]
}

Return statement

The return statement is to exit a function immediately with a numeric value.  By default, all functions return the value 0 at the end.  A return 0 instruction at the end of a function is therefore redundant and not needed (and takes up more precious processing time).

Syntax is as follows:

return [expression];

The expression may not be a string value.

#include Directive

The include compiler directive allows you to write reusable code in a separate file, and import them... or make your large scripts look prettier by breaking them into parts (such as the core script).  Only one main() function is allowed, so you may not #include complete scripts.

The syntax is:

#include "[filename]"

The imported code is added to the END of the script, not at the current point.  This is mainly to make sure that the main() function retains its position as the first function.  They are added in a first-in last-out fashion (a stack), so the first #include will be the last file actually imported.  Make sure your separate files do not import each other, there is no need for making infinite loops here.  If over 100 files are imported, the compiler will stop and assume there is a redundancy error.