elseif
The elseif command gives an if construct another test, tried when the earlier ones were false.
Syntax
elseif ( <expression> ) then
expression is as for if. The word then is required, and elseif stands alone on its line.
What it does
If no earlier branch of the construct was taken, James tests the expression. When it is true, James reads the branch that follows; when it is false, James skips to the next elseif, else or endif. Once a branch is taken, James skips every later one without testing it.
When James applies it
By the command parser, when it is read. The branch not taken is skipped. It is legal in any phase: Control, Part or Merge.
Rules James adds
- An
elseifafter anelsein the same construct is an error. - A guard in a branch that is not reached is never evaluated, so an undefined parameter there raises nothing.
Diagnostics
- E0304: the
elseiffollows anelsein the same construct. - E0313: there is no open
iffor it to continue. - E0309: the keyword shares its line with other input.
- E0317: the
thenis missing. - E0203: a guard names a parameter that has no value yet.
- E0221: a guard is not a well-formed expression, for example one that holds a
[ ].
Example
The script tests/corpus/161-elseif-branch-taken/input.tg, which make test runs:
c the elseif branch is the one taken, so one part from that branch is built
para n 2;
if(%n.eq.1)then
block 1 2;1 2;1 2;0 1;0 1;0 1;
elseif(%n.eq.2)then
block 1 2;1 2;1 2;0 2;0 1;0 1;
else
block 1 2;1 2;1 2;0 3;0 1;0 1;
endif
endpart
n is 2, so the first test is false and the elseif test is true. The prep dump shows the if and elseif lines with 2 in place of %n, and only the second block line. The IR holds one part with coord [0 2] along i.