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"

Line 4: Line 4:
  
 
Assign x to y
 
Assign x to y
<source lang="java">
+
<source lang="pascal">
 
y = x;
 
y = x;
 
</source>  
 
</source>  
  
 
If-then statement
 
If-then statement
<source lang="java">
+
<source lang="pascal">
 
if ( x > 4 )
 
if ( x > 4 )
 
   x = y;
 
   x = y;
Line 16: Line 16:
  
 
If-then-else statement
 
If-then-else statement
<source lang="java">
 
if ( x > 4 )
 
  x = y;
 
else
 
  x = 10;
 
end
 
</source>
 
 
<source lang="pascal">
 
<source lang="pascal">
 
if ( x > 4 )
 
if ( x > 4 )
Line 32: Line 25:
  
 
While loop
 
While loop
<source lang="java">
+
<source lang="pascal">
 
while ( x > 0 )
 
while ( x > 0 )
 
   counter += 1;
 
   counter += 1;
Line 40: Line 33:
  
 
Call a function
 
Call a function
<source lang="java">
+
<source lang="pascal">
 
doSomething();
 
doSomething();
 
</source>  
 
</source>  
  
 
Call a function, passing in parameters, and assign the result to a variable
 
Call a function, passing in parameters, and assign the result to a variable
<source lang="java">
+
<source lang="pascal">
 
z = doSomethingElse( 1, x, "hello", true );
 
z = doSomethingElse( 1, x, "hello", true );
 
</source>  
 
</source>  
  
 
Return from a function
 
Return from a function
<source lang="java">
+
<source lang="pascal">
 
return;
 
return;
 
</source>  
 
</source>  
  
 
Return a value from a function
 
Return a value from a function
<source lang="java">
+
<source lang="pascal">
 
return ( x );
 
return ( x );
 
</source>  
 
</source>  
  
 
Take one action out of several alternatives, depending on the value of an expression
 
Take one action out of several alternatives, depending on the value of an expression
<source lang="java">
 
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>
 
 
<source lang="pascal">
 
<source lang="pascal">
 
case ( pickles + 57 + LIMIT )
 
case ( pickles + 57 + LIMIT )
Line 90: Line 69:
  
 
Exception handling with the try-onException statement
 
Exception handling with the try-onException statement
<source lang="java">
+
<source lang="pascal">
 
try
 
try
 
   addToAccount( 100 );
 
   addToAccount( 100 );
Line 100: Line 79:
  
 
Handling more than one kind of exception
 
Handling more than one kind of exception
<source lang="java">
+
<source lang="pascal">
 
try
 
try
 
   addToAccount( 100 );
 
   addToAccount( 100 );

Revision as of 16:38, 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 alternatives, depending on the value of an expression

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

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

Back to the top