LexiScript allows for complex
flow control, that is, selectively running portions of the script based on various
conditions.
There are 2 kinds of conditions: if blocks and switch blocks.
if blocks allow you to only execute a portion of the script if some condition is true. If the condition is false, you can then run another portion of script if another condition is true, or run a portion of script if the condition was false.
Every
if needs a matching
end. This rule must not be broken or your script will have unwanted behavior.
The simplest form is below. A single condition and block of code.
if %foo%
... CODE IF FOO IS TRUE ...
end
The more complex form has a single condition, and two blocks of code.
if %foo%
... CODE IF FOO IS TRUE ...
else
... CODE IF FOO IS FALSE ...
end
The next form has two conditions, and two blocks of code. Note that it is
elseif not
else if, and because it is
elseif not
if, we don't need a matching end.
if %foo%
... CODE IF FOO IS TRUE ...
elseif %bar%
... CODE IF FOO IS FALSE AND BAR IS TRUE ...
end
The final form has 2 conditions and 3 blocks of code, mixing
elseif and
else.
if %foo%
... CODE IF FOO IS TRUE ...
elseif %bar%
... CODE IF FOO IS FALSE AND BAR IS TRUE ...
else
... CODE IF BOTH FOO AND BAR ARE FALSE ...
end
To summarize, if blocks consist of:
- Begin with an
if
- Follow with zero or more
elseif
- Follow with zero or one
else
- Follow with an
end
You can put
if blocks within
if blocks, but every
if must have an
end:
if %foo%
if %baz%
... CODE IF FOO IS TRUE AND BAZ IS TRUE ...
end
... CODE IF FOO IS TRUE (EVEN IF BAZ IS TRUE) ...
elseif %bar%
... CODE IF FOO IS FALSE AND BAR IS TRUE ...
end
--
FearItself - 27 Mar 2005