next up previous contents index
Next: Other remarks Up: Commands controlling program flow Previous: Other remarks

Looping while a condition is satisfied

   


tex2html_wrap_inline33790 tex2html_wrap_inline33790 Syntax

BD>while : E tex2html_wrap_inline33712

BD>... tex2html_wrap_inline33712

BD>...Body of commands tex2html_wrap_inline33712

BD>... tex2html_wrap_inline33712

BD>wend : tex2html_wrap_inline33712

where E is any valid equation.

tex2html_wrap_inline33806 tex2html_wrap_inline33806

The WHILE:  ...WEND:  construction is used to provide a loop surrounding a body of commands which will be processed as long as the rounded value of the equation E remains TRUE. An equation is defined to be TRUE if the rounded value of the equation is equal to unity, and FALSE otherwise. If no equation is given, or if a mistake is made in determining the equation, then [B/D] assumes that a valid equation with value FALSE has been supplied, so that the commands in the loop will not be processed.

Both the initiating WHILE:  and the terminating WEND:  command must be given on a separate line, and you should be careful not to confuse separate while ...end structures where you are nesting them.

As an example, consider the following program fragment.

BD>c : %i=0 tex2html_wrap_inline33712

BD>while : %i<2 tex2html_wrap_inline33712

BD>c : %i=%i+1 tex2html_wrap_inline33712

BD>c : %j=0 tex2html_wrap_inline33712

BD>repeat : tex2html_wrap_inline33712

BD>c : %j=%j+1 tex2html_wrap_inline33712

BD>print : (%i), (%j) tex2html_wrap_inline33712

BD>until : %j=2 tex2html_wrap_inline33712

BD>wend : %i=2 tex2html_wrap_inline33712

This code establishes two loops during which the constants take the values (%i=1,%j=1), (%i=1,%j=2), (%i=2,%j=1), (%i=2,%j=2), and then terminate.





David Wooff
Wed Oct 21 15:14:31 BST 1998