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

Conditional statements

     


tex2html_wrap_inline33790 tex2html_wrap_inline33790 Syntax

  1. BD>if : E tex2html_wrap_inline33712

    BD>... tex2html_wrap_inline33712

    BD>...Body of commands tex2html_wrap_inline33712

    BD>... tex2html_wrap_inline33712

    BD>endif : tex2html_wrap_inline33712

  2. BD>if : E tex2html_wrap_inline33712

    BD>... tex2html_wrap_inline33712

    BD>...Body of commands tex2html_wrap_inline33712

    BD>... tex2html_wrap_inline33712

    BD>else : tex2html_wrap_inline33712

    BD>... tex2html_wrap_inline33712

    BD>...Body of commands tex2html_wrap_inline33712

    BD>... tex2html_wrap_inline33712

    BD>endif : tex2html_wrap_inline33712

  3. BD>if : E tex2html_wrap_inline33876 command tex2html_wrap_inline33876 command tex2html_wrap_inline33876 ... tex2html_wrap_inline33712

  4. BD>if : E tex2html_wrap_inline33876 command tex2html_wrap_inline33876 command tex2html_wrap_inline33876 ... tex2html_wrap_inline33876 else : tex2html_wrap_inline33876 command tex2html_wrap_inline33876 command tex2html_wrap_inline33876 ... tex2html_wrap_inline33712

E is any valid equation.

tex2html_wrap_inline33806 tex2html_wrap_inline33806

These constructions are used to make program flow conditional on some aspect defined by the user. The value of the equation E is used to decide upon the appropriate course of action. In the context of if-then-else constructions, an equation is defined to be TRUE if the rounded value of the equation is equal to unity, and FALSE otherwise (the kind of rounding is defined in Appendix A). Therefore, if the value of the equation following the IF:  command is equal to unity, the body of commands immediately following will be processed.

The first and second forms of the syntax are our standard implementations, and the remaining two are more limited, but rather simpler, implementations designed to avoid some of the problems that arise from [B/D] being an interpreted language.

If the first form of the syntax is used, if the equation is TRUE, then the body of commands up to the ENDIF:  command is processed in the usual way. If, however, the equation is false, none of the commands between the IF:  and ENDIF:  are processed. In either case, the ENDIF:  command terminates the construction.

If the second form of the syntax is used, if the equation is TRUE, then the body of commands up to the ENDIF:  command is processed in the usual way. If, however, the equation is false, none of the commands between the IF:  and ENDIF:  are processed and instead the body of commands between the ELSE:  and ENDIF:  commands are processed. In either case, the ENDIF:  command terminates the construction.

The final two forms of the syntax are special forms, which we will call one-line IF:  statements. They consist of the IF:  statement, together with one or more commands separated by the symbol ` tex2html_wrap_inline33876 ', on the same line. The fourth form shows that the ELSE:  command may be included to provide an alternative set of commands to process if the condition turns out to be FALSE. Notice that the ENDIF:  command is not (and may not) used to mark the end of the loop: the end-of-line marker does this instead.




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

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