Logic, Flow Control and Iteration
This section describes how to use a few SurferScript tags to control how your SurferScript executes.
<TEIF
expression {= | > | < | <> | >= | <= }expression
[AND | OR] ...>
Provides logical control for your templates. If the condition entered
is TRUE, the HTML and macro tags occurring in the file between the <TEIF
condition> and following <TEELSE> or </TEIF> is executed.
If the condition entered is FALSE, if there is a following <TEELSE>
prior to a </TEIF> than that block will be executed; otherwise, nothing
will be executed up to and including the following </TEIF> tag.
<TEELIF
expression {= | > | < | <> | >= | <= }expression
[AND | OR] ...>
The TEELIF tag is used to provide an alternate BOOLEAN expression should any preceeding TEIF or TEELIF not evaluate to TRUE.
TEELIF Example
|
 |
<TEIF screen(row,2,1)="A">
Author: <B><TESHOW screen(row, 5, 75)></B>
<TEELIF screen(row,2,1)="T">
Title: <B><TESHOW screen(row, 5, 75)></B>
<TEELIF screen(row,2,1)="L">
Location: <B><TESHOW screen(row, 5, 75)></B>
<TEELSE>
Unrecognized! (<B><TESHOW screen(row, 5, 75)></B>)
</TEIF>
|
|
 |
In this example, the current screen row (identified by the local-scope variable "row") is displaying one of three descriptions: an Author, a Title or a Location. On the mainframe, just the letters "A", "T" or "L" are used as "codes". This example checks the code and displays more informative text instead.
|  |
|
TEELSE Works with TEIF to Control how HTML
and macro tags are sent
<TEELSE>
When present between a <TEIF> (or the last TEELIF) and </TEIF> tag, provides a marker for the "false" action. If the corresponding <TEIF> tag is FALSE, the HTML and macros between any following TEELSE will be executed up to the next </TEIF>, end of the section or end of the template file. See both the TEIF and TEELIF samples for examples of use.
TELOOP Provides an iteration mechanism for
template logic
<TELOOP
{[name=]VariableName}
{[first=]FirstValueExpression}
{[last=]LastValueExpression}
[[step=]StepExpression]>
Where:
Name (required) |
Is the name of the variable which will have its value iterated from
the first value to the last value in steps defined by StepExpression. You may change the value of this variable inside the loop (for example, to skip a blank row while iterating within a screen). If you do change the value of this variable, the next iteration through the loop will apply the active step expression to the new value |
FirstValueExpression |
An integer expression providing the initial value-- once the loop has
been entered, changing any variables in this expression will have no effect
on the loop continuation |
LastValueExpression |
An integer expression providing the last value-- this value may be
changed following the start of the loop, although it should never be changed
so that the loop will run unchecked. |
StepExpression |
An integer expression providing the step value. If this expression includes any variables, their value may
be changed during the loop to affect the next iteration, although never change the sign of the step
expression- if at compile-time the step is negative, keep it that way!
Default Value=1 |
The TELOOP macro provides simple initialization, iteration and termination
control. The block of HTML and macros between the opening <TELOOP> and
closing </TELOOP> will execute repeatedly based on the defined iteration
of the integer variable value. One or more <TEBREAK>
tags may also be included in the body of the loop; when executed, a <TEBREAK>
will break-out of the loop.
Note that both the <TELOOP> and </TELOOP> must be in the same
template file, as well as any associated <TEBREAK> statements.
Also, you can nest TELOOP statements up to 20 levels...if you need more
than 20 levels, you should talk to someone about your approach...maybe
take a break, or go for a walk.
TELOOP Example
|
 |
<TABLE>
<TR><TH>Name</TH><TH>Position</TH></TR>
<TELOOP EmpRow First=5 Last=20 Step=1>
<TEIF Screen(EmpRow,10,1)=" ">
<TEBREAK>
</TEIF>
<TR>
<TD><TEDATA EmpRow 10 20></TD>
<TD><TEDATA EmpRow 30 50></TD>
</TR>
</TELOOP>
</TABLE>
|
|
 |
Starting at Row 5, display two fields starting at columns 10
and 30 on each row up until row 20, also stop if any of the rows has a
blank in column 10.
|  |
|
TEBREAK Immediately Exit an active <TELOOP>
<TEBREAK>
The TEBREAK statement will "jump" to the end of the current <TELOOP>
section, whenever it is encountered. Typically, you will put a TEBREAK
statement inside a conditional <TEIF> in order to avoid continuing a
loop when it is unnecessary to, such as encountering the end of a list.
You can include as many TEBREAK statements as you like inside a given
TELOOP block.
See the coding example in the <TELOOP> section.