Flow Control OperatorsElzed includes a generous number of flow control operators. This is one of the features which makes Elzed really versatile. The following operators are built in:
if....then...else & unless...then...else
An old favorite. The else is optional, of course. In use they look something like this:
if ( y<15 ) then x--; y++; else x++; y++; end
unless ( y>=15 ) then x--; y++; else x++; y++; end
Of course, you can get more complicated:
if ( (y+1)<=15 ) then
if ( (x-1)>=0 ) then
unless ( b[ x-1, y+1 ] < 1 ) then
neighbors++;
end
end
end
You may nest flow control operators to any arbitrary depth, limited only by RAM. Use "end" to terminate an if or unless.
while...do & until...do
The difference between while and until is that the until loop will always be done at least once, even though the loop test appears at the top in both cases. Note the use of "next" to mark the end of the loop.
while ( x < 16 ) do
b[ x++, y ] = 0;
next
until ( x == 16 ) do
b[ x++, y ] = 0;
next
break & continue
Break jumps out of the nearest enclosing loop structure or select structure. Continue forces the next iteration of a loop.
select...case...default & when...is...otherwise
Similar to the C/C++ switch-case structure. The default case is optional. While it may appear anywhere within the structure, it's good form to put the default either at the end or the beginning of the list of cases.
select( b[ x, y ] )
case (-1):
b[ x, y ] = 1;
replace( board[ y ], "O", x, 1 );
break;
case 0:
replace( board[ y ], " ", x, 1 );
break;
case 1:
replace( board[ y ], "O", x, 1 );
break;
case 2:
b[ x, y ] = 0;
replace( board[ y ], " ", x, 1 );
break;
default:
b[ x, y ] = 0;
replace( board[ y ], " ", x, 1 );
break;
end
Use end to terminate a select...case.
The when...is...otherwise structure works the same way as select...case...default, just with more readable keywords:
when( b[ x, y ] )
is (-1):
b[ x, y ] = 1;
replace( board[ y ], "O", x, 1 );
break;
is 0:
replace( board[ y ], " ", x, 1 );
break;
is 1:
replace( board[ y ], "O", x, 1 );
break;
is 2:
b[ x, y ] = 0;
replace( board[ y ], " ", x, 1 );
break;
otherwise:
b[ x, y ] = 0;
replace( board[ y ], " ", x, 1 );
break;
end
return & exit
Stops evaluating an expression. Return has the additional option of sending a value back to the caller, and is the way an expression operator passes back its result.
return neighbors;
exit;
goto...label
When you need it, you really need it. Goto jumps to a predefined label in an expression.
label infinite:
x++;
goto infinite;
seterror & clearerror
Seterror places the current context in the indicated error state, while clearerror clears the current context's error state.
seterror 1310;
clearerror; |