Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EDT:Writing statements"
(→Continue) |
(→Continue) |
||
Line 54: | Line 54: | ||
== 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 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 following example assumes that you have coded a print function named printReport. | The following example assumes that you have coded a print function named printReport. |
Revision as of 14:07, 13 February 2012
EGL provides general statements such as if and while, as well as action statements for accessing data sources or invoking external logic.
Contents
General statements
The general statements are case, continue, exit, for, if, move, return, throw, try, use, and while.
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 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 following example assumes that you have coded a print function named printReport.
for (i from 1 to 100 by 1) printReport(myList[i]); if ((i % 10) != 0) continue; end // if printReport(blankLine); end // for
That code prints the members of a list, inserting a blank line between each group of ten.
Exit
For
If
Move
Return
Throw
Try
Use
While
Action statements
The action statements are add, call, close, delete, execute, forEach, get, open, prepare, and transfer.