|
|
(7 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="java">
| |
− | y = x;
| |
− | </source>
| |
− |
| |
− | If-then statement
| |
− | <source lang="java">
| |
− | if ( x > 4 )
| |
− | x = y;
| |
− | end
| |
− | </source>
| |
− |
| |
− | If-then-else statement
| |
− | <source lang="java">
| |
− | if ( x > 4 )
| |
− | x = y;
| |
− | else
| |
− | x = 10;
| |
− | end
| |
− | </source>
| |
− |
| |
− | While loop
| |
− | <source lang="java">
| |
− | while ( x > 0 )
| |
− | counter += 1;
| |
− | x -= 1;
| |
− | end
| |
− | </source>
| |
− |
| |
− | Call a function
| |
− | <source lang="java">
| |
− | doSomething();
| |
− | </source>
| |
− |
| |
− | Call a function, passing in parameters, and assign the result to a variable
| |
− | <source lang="java">
| |
− | z = doSomethingElse( 1, x, "hello", true );
| |
− | </source>
| |
− |
| |
− | Return from a function
| |
− | <source lang="java">
| |
− | return;
| |
− | </source>
| |
− |
| |
− | Return a value from a function
| |
− | <source lang="java">
| |
− | return ( x );
| |
− | </source>
| |
− |
| |
− | Take one action out of several, based on the value of an expression
| |
− | <source lang="java">
| |
− | 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
| |
− | </source>
| |
− |
| |
− | Exception handling with the try-onException statement
| |
− | <source lang="java">
| |
− | 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="java">
| |
− | 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>
| |
− |
| |
− | [[Category:EDT]]
| |