Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EDT:Writing statements"

(If)
(Function invocation)
 
(45 intermediate revisions by 4 users not shown)
Line 1: Line 1:
EGL provides ''general statements'' such as '''if''' and '''while''', as well as ''action statements'' for accessing data sources or invoking external logic.  
+
This page contains code snippets for statement.
 +
 
 +
EGL provides two kinds of statements:
 +
 
 +
*[[#General_statements|General statements]] such as '''if''' and '''while''', for processing the data that is immediately available to your logic.<br>
 +
*[[#Action_statements|Action statements]] such as '''add''' and '''call''', for accessing external data sources or invoking external logic. <br>
 +
 
 +
= 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.
 +
<source lang="java">
 +
x = // This is a line comment.
 +
1;
 +
y /* This is a block comment.  It
 +
    extends
 +
  over
 +
        five
 +
    lines. */  =  /* This is another block comment. */  2;
 +
</source>
 +
The previous example has the same effect as these statements:
 +
<source lang="java">
 +
x = 1;
 +
y = 2;
 +
</source>
  
 
= General statements  =
 
= General statements  =
  
The general statements are [[#case|case]], [[#continue|continue]], [[#exit|exit]], [[#for|for]], [[#if|if]], [[#move|move]], [[#return|return]], [[#throw|throw]], [[#try|try]], [[#use|use]], and [[#while|while]].  
+
The general statements are [[#assignment|assignment]], [[#case|case]], [[#continue|continue]], [[#declaration|declaration]], [[#exit|exit]], [[#for|for]], [[#function invocation|function invocation]], [[#if|if]], [[#return|return]], [[#throw|throw]], [[#try|try]], [[#use|use]], and [[#while|while]].  
 +
 
 +
== 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.
 +
 
 +
<source lang="java">
 +
function areaOfCircle(radius int) returns(float)
 +
  pi decimal(9,8);
 +
 
 +
  pi = 3.14159265;
 +
  area float = pi * radius * radius;
 +
  return(area);
 +
end
 +
</source>
 +
 
 +
The EGL string type provides various functions for isolating substrings.  Here is an example use.
 +
 
 +
<source lang="java">
 +
 
 +
function EGL_offers()   
 +
  myStringVar01 STRING = "EGL offers ease of coding.";
 +
  myStringVar02 STRING = "True.  An elegant language offers ease of coding and ease of thought.";
 +
       
 +
  endOfFirstPhrase INT = myStringVar01.indexOf(" ease");
 +
  startOfSecondPhrase INT = myStringVar02.lastIndexOf("ease");
 +
                     
 +
  myStringVar03 STRING = myStringVar01[1:endOfFirstPhrase] +
 +
                          myStringVar02[startOfSecondPhrase:myStringVar02.length()-1] +
 +
                          ", too.";
 +
       
 +
  SysLib.writeStdOut(myStringVar03);  // output:  "EGL offers ease of thought, too."
 +
end
 +
end
 +
 
 +
 
 +
 
 +
 
 +
</source>
  
 
== Case  ==
 
== Case  ==
Line 54: Line 123:
 
== Continue  ==
 
== Continue  ==
  
The EGL 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 '''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 following example assumes that you have coded a print function named printReport.
+
Here is an example:
  
 
<source lang="java">
 
<source lang="java">
for (i from 1 to 100 by 1)
+
inputList int[] = [2, 4, 6, 8, 10, 12, 14, 16];
  
   printReport(myList[i]);
+
for(i int from 1 to inputList.getSize() by 1)
 
+
   SysLib.writeStdOut(inputList[i]);
   if ((i % 10) != 0)
+
 
 +
   if((i % 3) != 0)
 
       continue;
 
       continue;
 
   end // if
 
   end // if
 
+
           
   printReport(blankLine);
+
   SysLib.writeStdOut(" ");
end // for
+
end  
</source>
+
</source>  
  
That code prints the members of a list, inserting a blank line between each group of ten.
+
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.
 +
 
 +
<source lang="java">
 +
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.
 +
</source>
  
 
== Exit  ==
 
== Exit  ==
  
The EGL 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.
+
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  ==
 
== For  ==
  
<br>  
+
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.
 +
 
 +
<source lang="java">
 +
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 1
 +
      for(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
 +
</source> <br>
 +
 
 +
In each case, the variable <code>i</code> was local to the '''for''' statement. Here is an alternative:
 +
 
 +
<source lang="java">
 +
i int;
 +
 
 +
for(i from 1 to numberInList)
 +
  sum = inputList[i] + sum;
 +
end
 +
</source>
 +
 
 +
After that code ends, the value of <code>i</code> is available and equals <code>numberInList + 1</code>.&nbsp;
 +
 
 +
== 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.
 +
<source lang="java">
 +
program HelloWorld
 +
  function main()
 +
    SysLib.writeStdout( "Hello world!" );
 +
  end
 +
end
 +
</source>
 +
 
 +
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.)
 +
 
 +
<source lang="java">
 +
program TestProgram
 +
  function main()
 +
    myFunctions RunFunction[] = [foo, bar];
 +
    myFunctions[1]();
 +
    myFunctions[2]();
 +
  end
 +
 
 +
  function foo()
 +
    SysLib.writeStdout("foo");
 +
  end
 +
 +
  function bar()
 +
    SysLib.writeStdout("bar");
 +
  end
 +
end
 +
</source>
  
 
== If  ==
 
== If  ==
  
The following program shows If statements embedded in other If statements.&nbsp;&nbsp;
+
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. <br><br>The following code shows how to embed '''If''' statements in other '''If''' statements.&nbsp;&nbsp;  
  
 
<source lang="java">
 
<source lang="java">
  
 
program MyTestProgram
 
program MyTestProgram
 +
 +
  // A binary search finds a value in a sorted (preferably short) list.
 +
  function binarySearch(list int[], lowIndex int, highIndex int, value int) returns(int)
 +
 +
      middleIndex int;
 +
 +
      while(true)
 +
        middleIndex = (lowIndex + highIndex) / 2;
 +
 +
        if(list[middleIndex] == value)
 +
            return(middleIndex);
 +
        else
 +
            if(list[middleIndex] > value)
 +
              highIndex = middleIndex - 1;
 +
            else
 +
              if(list[middleIndex] < value)
 +
                  lowIndex = middleIndex + 1;
 +
              end
 +
            end
 +
        end
 +
 +
        if(highIndex < lowIndex)
 +
            return(-1);
 +
        end
 +
      end
 +
  end
 +
     
  
 
   function main()
 
   function main()
Line 93: Line 288:
 
       myNumbers int[] =[-6, -1, 2, 4, 7, 9 ];
 
       myNumbers int[] =[-6, -1, 2, 4, 7, 9 ];
 
       valueOfInterest int = -1;
 
       valueOfInterest int = -1;
       
+
 
 
       lowestIndex int = 1;
 
       lowestIndex int = 1;
 
       highestIndex int = myNumbers.getSize();
 
       highestIndex int = myNumbers.getSize();
  
       location int = binarySearch(myNumbers, lowestIndex, highestIndex,
+
       location int = binarySearch(myNumbers, lowestIndex, highestIndex, valueOfInterest);
                        valueOfInterest);
+
 
        
 
        
 
       if (location == -1)
 
       if (location == -1)
Line 106: Line 300:
 
                             ", at location " + location + ".");
 
                             ", at location " + location + ".");
 
       end
 
       end
    end
+
  end
 +
end
  
    function binarySearch(list int[], lowIndex int, highIndex int, value int) returns(int)
 
  
        while(true)
+
</source>
            middleIndex int = (lowIndex + highIndex) / 2;
+
  
            if(list[middleIndex] == value)
+
<br><br>
                return(middleIndex);
+
            else
+
                if(list[middleIndex] >= value)
+
                    highIndex = middleIndex - 1;
+
                else
+
                    if(list[middleIndex] < value)
+
                        lowIndex = middleIndex + 1;
+
                    end
+
                end               
+
            end
+
  
            if(highIndex < lowIndex)
+
== Return  ==
                return(-1);
+
 
            end
+
<source lang="java">
        end
+
  
    end         
 
 
</source>  
 
</source>  
  
The binary search provides a way to find for a value in a short, sorted list. <br><br>
+
== Throw  ==
  
== Move  ==
+
<source lang="java">
  
<br>  
+
</source>  
  
== Return ==
+
== Try ==
  
<br>
+
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'''.
  
== Throw  ==
+
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.
  
== <br> Try  ==
+
An onException block for the type AnyException will "catch" every Exception that's not handled by any other onException block of the try statement.
  
<br>  
+
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.
 +
 
 +
<source lang="java">
 +
try
 +
  addToAccount( 100 );
 +
  deductFromAccount( 100 );
 +
onException ( ex1 AddException )
 +
  handleException( ex1, "add" );
 +
onException ( ex2 DeductException )
 +
  handleException( ex2, "deduct" );
 +
onException ( ex3 PasswordException )
 +
  handleException( ex3, "password" );
 +
onException ( ex4 AnyException )
 +
  handleException( ex4, "other" );
 +
end
 +
</source>
 +
 
 +
The order of the onException blocks does not matter, though by convention an onException block for AnyException is specified last.
  
 
== Use  ==
 
== Use  ==
  
<br>  
+
<source lang="java">
 +
 
 +
</source>  
  
 
== While  ==
 
== While  ==
  
<br>  
+
<source lang="java">  
 +
 
 +
</source>
 +
 
  
 
= Action statements  =
 
= Action statements  =
  
The action statements are [[#add|add]], [[#call|call]], [[#close|close]], [[#delete|delete]], [[#execute|execute]], [[#forEach|forEach]], [[#get|get]], [[#open|open]], [[#prepare|prepare]], and [[#transfer|transfer]].<br>  
+
The action statements are [[#add|add]], [[#call|call]], [[#close|close]], [[#delete|delete]], [[#execute|execute]], [[#forEach|forEach]], [[#get|get]], [[#open|open]], and [[#prepare|prepare]].
 +
 
 +
Except for the '''call''' statement, all are now used for accessing a relational database.  
 +
 
 +
<br>  
  
 
== Add  ==
 
== Add  ==
 +
 +
<source lang="java">
 +
 +
</source>
 +
  
 
== Call  ==
 
== Call  ==
 +
 +
In EDT version .8:
 +
 +
<source lang="java">
 +
call MyInterfaceType.theFunction)  using "binding.myService"
 +
                                  returning to myCallBackFunction
 +
                                  onException myExceptionHandler;     
 +
</source>
 +
 +
In EDT version .7:
 +
 +
<source lang="java">
 +
myService MyServiceType?{@Resource};
 +
call myServiceVariable.theFunction() returning to myCallBackFunction
 +
                                    onException myExceptionHandler;     
 +
</source>
 +
 +
For further details, see [[EDT:Accessing a service|Accessing a service]]
  
 
== Close  ==
 
== Close  ==
 +
 +
<source lang="java">
 +
 +
</source>
 +
 +
  
 
== Delete  ==
 
== Delete  ==
 +
 +
<source lang="java">
 +
 +
</source>
 +
 +
  
 
== Execute  ==
 
== Execute  ==
 +
 +
<source lang="java">
 +
 +
</source>
 +
 +
  
 
== ForEach  ==
 
== ForEach  ==
 +
 +
 +
<source lang="java">
 +
 +
</source>
 +
  
 
== Get  ==
 
== 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.
 +
 +
<source lang="java">
 +
  try
 +
    get jobsRecords from dataSource using dateYYYYMMDD, timeHHMMSS  with 
 +
    #sql{ 
 +
        select JBNAME, JBUSER, JBNUMBER, JBIJOBID, JBSTATUS, JBTYPE, JBSUBTYP,
 +
        JBSBSNAM, JBSBSLIB, JBPERCENT, JBSAMPLEDT, JBSAMPLETM
 +
        from  SYSJOBSP  where JBSAMPLEDT = ?  and JBSAMPLETM = ?
 +
        order by JBPERCENT desc
 +
        fetch first 10 rows only
 +
    };
 +
  onException(ex sqlException)
 +
    logException(ex);
 +
  end 
 +
</source>
  
 
== Open  ==
 
== Open  ==
 +
 +
<source lang="java">
 +
 +
</source>
 +
 +
  
 
== Prepare  ==
 
== Prepare  ==
  
== Replace ==
+
<source lang="java">
 +
 
 +
</source>
 +
 
 +
 
 +
== Replace ==
 +
 
 +
<source lang="java">
 +
 
 +
</source>
 +
<br> <br><br> ♦ [[EDT:Code snippets|Code snippets main page]] <br>
  
== Transfer ==
+
[[Category:EDT]]

Latest revision as of 12:56, 4 September 2012

This page contains code snippets for statement.

EGL provides two kinds of statements:

  • General statements such as if and while, for processing the data that is immediately available to your logic.
  • Action statements such as add and call, for accessing external data sources or invoking external logic.

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

The general statements are assignment, case, continue, declaration, exit, for, function invocation, if, return, throw, try, use, and while.

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.

function areaOfCircle(radius int) returns(float)
   pi decimal(9,8);
 
   pi = 3.14159265;
   area float = pi * radius * radius;
   return(area);
end

The EGL string type provides various functions for isolating substrings. Here is an example use.

function EGL_offers()    	 	
   myStringVar01 STRING = "EGL offers ease of coding.";
   myStringVar02 STRING = "True.  An elegant language offers ease of coding and ease of thought."; 
 
   endOfFirstPhrase INT = myStringVar01.indexOf(" ease");
   startOfSecondPhrase INT = myStringVar02.lastIndexOf("ease");
 
   myStringVar03 STRING = myStringVar01[1:endOfFirstPhrase] + 
                          myStringVar02[startOfSecondPhrase:myStringVar02.length()-1] +
                          ", too."; 
 
   SysLib.writeStdOut(myStringVar03);  // output:  "EGL offers ease of thought, too."
 end
end

Case

The case statement responds to conditions at run time by executing one set of statements rather than another:

  • You can test a criterion value. The following example invokes mySecondFunction:
function test()
   x Int = 3; 
 
   case (x)
      when (1)
         myFirstFunction();
      when (2, 3, 4)
         mySecondFunction();      
      otherwise
         myDefaultFunction();
   end   
end
  • You can test a set of logical expressions. The following example displays only "x passes":
function test()
   x Int = 3;
   y Int = 5;
   z Int = 7;
 
   case
      when (x == 3)
         SysLib.writeStdOut("x passes");
      when (y == 5)
         SysLib.writeStdOut("y passes");
      when (z == 7)
         SysLib.writeStdOut("z passes");
      otherwise
         SysLib.writeStdErr("You will not see this message.");
      end
   end 
end

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.

Here is an example:

inputList int[] = [2, 4, 6, 8, 10, 12, 14, 16];
 
for(i int from 1 to inputList.getSize() by 1)
   SysLib.writeStdOut(inputList[i]);
 
   if((i % 3) != 0)
      continue;
   end // if
 
   SysLib.writeStdOut(" ");
end

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 1
      for(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.)

program TestProgram
  function main()
    myFunctions RunFunction[] = [foo, bar];
    myFunctions[1]();
    myFunctions[2]();
  end
 
  function foo()
    SysLib.writeStdout("foo");
  end
 
  function bar()
    SysLib.writeStdout("bar");
  end
end

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.  

program MyTestProgram
 
   // A binary search finds a value in a sorted (preferably short) list.
   function binarySearch(list int[], lowIndex int, highIndex int, value int) returns(int)
 
      middleIndex int;
 
      while(true)
         middleIndex = (lowIndex + highIndex) / 2;
 
         if(list[middleIndex] == value)
            return(middleIndex);
         else
            if(list[middleIndex] > value)
               highIndex = middleIndex - 1;
            else
               if(list[middleIndex] < value)
                  lowIndex = middleIndex + 1;
               end
            end
         end
 
         if(highIndex < lowIndex)
            return(-1);
         end
      end
   end
 
 
   function main()
 
      myNumbers int[] =[-6, -1, 2, 4, 7, 9 ];
      valueOfInterest int = -1;
 
      lowestIndex int = 1;
      highestIndex int = myNumbers.getSize();
 
      location int = binarySearch(myNumbers, lowestIndex, highestIndex, valueOfInterest);
 
      if (location == -1)
         SysLib.writeStdOut("Did not find " + valueOfInterest + ".");
      else
         SysLib.writeStdOut("The value of interest is " + valueOfInterest +
                            ", at location " + location + ".");
      end
   end
end



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.

try
  addToAccount( 100 );
  deductFromAccount( 100 );
onException ( ex1 AddException )
  handleException( ex1, "add" );
onException ( ex2 DeductException )
  handleException( ex2, "deduct" );
onException ( ex3 PasswordException )
  handleException( ex3, "password" );
onException ( ex4 AnyException )
  handleException( ex4, "other" );
end

The order of the onException blocks does not matter, though by convention an onException block for AnyException is specified last.

Use

 

While

 


Action statements

The action statements are add, call, close, delete, execute, forEach, get, open, and prepare.

Except for the call statement, all are now used for accessing a relational database.


Add

 


Call

In EDT version .8:

call MyInterfaceType.theFunction)  using "binding.myService" 
                                   returning to myCallBackFunction
                                   onException myExceptionHandler;

In EDT version .7:

myService MyServiceType?{@Resource};
call myServiceVariable.theFunction() returning to myCallBackFunction
                                     onException myExceptionHandler;

For further details, see Accessing a service

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.

  try 
    get jobsRecords from dataSource using dateYYYYMMDD, timeHHMMSS   with  
    #sql{  
        select JBNAME, JBUSER, JBNUMBER, JBIJOBID, JBSTATUS, JBTYPE, JBSUBTYP, 
        JBSBSNAM, JBSBSLIB, JBPERCENT, JBSAMPLEDT, JBSAMPLETM 
        from   SYSJOBSP  where JBSAMPLEDT = ?  and JBSAMPLETM = ?
        order by JBPERCENT desc
        fetch first 10 rows only 
    };
  onException(ex sqlException)
    logException(ex);
  end

Open

 


Prepare

 


Replace

 




Code snippets main page

Back to the top