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 basic logic"
Line 1: | Line 1: | ||
== Basic EGL statements == | == Basic EGL statements == | ||
− | EGL's syntax is similar to C, Java, and other languages | + | EGL's basic syntax is similar to C, Java, and many other languages. |
Assign x to y | Assign x to y | ||
Line 51: | Line 51: | ||
return ( x ); | return ( x ); | ||
</source> | </source> | ||
− | |||
− | |||
− | |||
− | + | Take one action out of several, based on the value of an expression | |
<source lang="java"> | <source lang="java"> | ||
case ( x ) | case ( x ) | ||
Line 62: | Line 59: | ||
when ( 2, 3, 4 ) | when ( 2, 3, 4 ) | ||
y = 2; | y = 2; | ||
− | when ( "hello", z ) | + | when ( "hello", z, computerIsUnplugged() ) |
y = 3; | y = 3; | ||
− | when ( | + | when ( computerIsOnFire() || pickles + 57 > LIMIT ) |
y = 4; | y = 4; | ||
otherwise | otherwise |
Revision as of 16:07, 10 February 2012
Basic EGL statements
EGL's basic syntax is similar to C, Java, and many other languages.
Assign x to y
y = x;
If-then statement
if ( x > 4 ) x = y; end
If-then-else statement
if ( x > 4 ) x = y; else x = 10; end
While loop
while ( x > 0 ) counter += 1; x -= 1; end
Call a function
doSomething();
Call a function, passing in parameters, and assign the result to a variable
z = doSomethingElse( 1, x, "hello", true );
Return from a function
return;
Return a value from a function
return ( x );
Take one action out of several, based on the value of an expression
case ( x ) when ( 1 ) y = 1; when ( 2, 3, 4 ) y = 2; when ( "hello", z, computerIsUnplugged() ) y = 3; when ( computerIsOnFire() || pickles + 57 > LIMIT ) y = 4; otherwise y = 5; end
Exception handling with the try-onException statement
try addToAccount( 100 ); deductFromAccount( 100 ); onException ( ex AnyException ) SysLib.writeStderr( "Oh noes! " :: ex.message ); end
Handling more than one kind of exception
try addToAccount( 100 ); deductFromAccount( 100 ); onException ( ex1 AddException ) SysLib.writeStderr( ex1.message ); onException ( ex2 DeductException ) SysLib.writeStderr( ex2.message ); onException ( ex3 UserException ) SysLib.writeStderr( ex3.message ); end