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 basic logic"

(Removing all content from page)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Basic EGL statements  ==
 
  
EGL's basic syntax is similar to C, Java, and many other languages.
 
 
Assign x to y
 
<source lang="pascal">
 
y = x;
 
</source>
 
 
If-then statement
 
<source lang="pascal">
 
if ( x > 4 )
 
  x = y;
 
end
 
</source>
 
 
If-then-else statement
 
<source lang="pascal">
 
if ( x > 4 )
 
  x = y;
 
else
 
  x = 10;
 
end
 
</source>
 
 
While loop
 
<source lang="pascal">
 
while ( x > 0 )
 
  counter += 1;
 
  x -= 1;
 
end
 
</source>
 
 
Call a function
 
<source lang="pascal">
 
doSomething();
 
</source>
 
 
Call a function, passing in parameters, and assign the result to a variable
 
<source lang="pascal">
 
z = doSomethingElse( 1, x, "hello", true );
 
</source>
 
 
Return from a function
 
<source lang="pascal">
 
return;
 
</source>
 
 
Return a value from a function
 
<source lang="pascal">
 
return ( x );
 
</source>
 
 
Take one action out of several alternatives, depending on the value of an expression
 
<source lang="pascal">
 
case ( pickles + 57 + LIMIT )
 
  when ( 1 )
 
    y = 1;
 
  when ( 2, 3, 4 )
 
    y = 2;
 
  when ( "hello", z )
 
    y = 3;
 
  when ( x )
 
    y = 4;
 
  otherwise
 
    y = 5;
 
end
 
</source>
 
 
Exception handling with the try-onException statement
 
<source lang="pascal">
 
try
 
  addToAccount( 100 );
 
  deductFromAccount( 100 );
 
onException ( ex AnyException )
 
  SysLib.writeStderr( "Oh noes! " :: ex.message );
 
end
 
</source>
 
 
Handling more than one kind of exception
 
<source lang="pascal">
 
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
 
</source>
 
 
 
<br>
 
 
<br> <br>
 
 
 
 
♦ '''First''':&nbsp;&nbsp;[[EDT:Code_snippets|Code snippets main page]] <br>
 
 
 
[[Category:EDT]]
 

Latest revision as of 16:20, 14 February 2012

Back to the top