CSP and HTML Tag Reference
Delimits the body
of a WHILE loop.
||A server-side expression evaluated after each iteration.
If the expression evaluated to true, then the loop is iterated again.
||A server-side expression.
||The name of a local variable that is automatically incremented
upon each iteration.
||A valid variable name.
||For use with embedded SQL only. An SQL cursor that gets
the row for the next iteration.
||A valid SQL cursor name.
||For use with embedded SQL only. Comma-separated INTO list
for the SQL FETCH of the next row. Specifies the variables to receive the
||A comma-separated list of variables..
The CSP:WHILE tag repeatedly executes its contents while the server-side
expression specified by the CONDITION
attribute is true.
Upon each iteration, a local variable, specified by the COUNTER
is incremented. The counter variable is initialized to 0 before the loop and
is incremented at the beginning of each iteration. If the counter attribute
is not specified, no counter will be generated. The CSP:WHILE tag may also
be used to loop over a cursor defined for embedded SQL using the SCRIPT LANGUAGE=SQL
The basic structure of a CSP WHILE loop is:
are the attributes of the CSP:WHILE
tag (listed above) and content
is the content to display
during each iteration of the loop.
At the end of each iteration of a WHILE loop, a condition is evaluated
to determine whether the loop will execute again. If the condition is true,
another iteration of the loop is performed, but if the condition evaluates
to false the loop is exited. The relevant condition is specified using the CONDITION
of the CSP:WHILE tag:
is the expression to evaluate at the end
of each iteration.
You must specify a CONDITION
attribute for every
A WHILE loop can maintain a counter in a local variable. This counter
is incremented by 1 upon each iteration of the loop. The local variable used
as a counter is specified by the COUNTER
<CSP:WHILE CONDITION="cond" COUNTER="count">
is the name of the counter. The initial
value of the counter is always 0.
If you do not specify a COUNTER
the WHILE loop will not maintain a counter variable.
Using SQL in a WHILE Loop
You can define a static SQL cursor using the <SCRIPT> tag and then
use a WHILE loop to display the results of the query.
For example, the following code defines a static SQL cursor named query
<SCRIPT LANGUAGE=SQL CURSOR="query">
SELECT Name,SSN FROM Sample.Person ORDER BY Name
You can use a CSP:WHILE tag to iterate over this cursor as follows:
<CSP:WHILE CURSOR="query" INTO="name,ssn">
Name: #(name)#, SSN: #(ssn)# <BR>
attribute specifies the name of an SQL
cursor defined using a <SCRIPT> tag while the INTO
specifies a comma-delimited list of local variables into which the column
values retrieved by the query are placed in their respective order.
This simple WHILE loop displays the value of the counter during each
iteration of the loop:
<CSP:WHILE COUNTER="i" CONDITION="i<10">
<LI>The value of the counter is #(i)#.
Note that the < (less than) operator is represented using the HTML
< entity as HTML does not allow <, >, or &, within an attribute
value. This entity is interpreted as <
by the CSP page compiler
when it generates code for the WHILE loop.