B. Terminal Monitor : Branching
 
Share this page                  
Branching
The \branch and \mark commands permit arbitrary branching within an \include file. \mark must be followed with a label. Follow \branch with a label to indicate unconditional branch. To indicate conditional branch, follow \branch with an expression preceded by a question mark (?) and followed by a label. The branch is taken if the expression is greater than zero. For example, consider the following Terminal Monitor command:
\branch ?{ifsame;@{read Enter data:};a;1;0}=1 valueok
This command relies heavily on Terminal Monitor macros. Reading outward from the inside, the {read} macro writes "Enter data:" on the screen and accepts input from the terminal. {read} is preceded with an ''@'' sign, because it must be pre-scanned in this expression. see Parameter Prescan.
The result of the {read} macro, that is, what is typed at the terminal, becomes the first string in an {ifsame} macro. The {ifsame} macro compares what is entered to ''a''. If "a" is entered, the value of {ifsame} is 1. If anything other than "a" is entered, the value of {ifsame} is 0. If the result of this nesting of system macros is 1, the Terminal Monitor branches to label ''valueok'' (that is, if the letter "a" is entered at the terminal).
The expressions usable in \branch statements are somewhat restricted. The following operators are defined in the usual way: +, -, *, /, >, >=, <, <=, != and =. The left unary operator ! can be used to indicate logical negation. There cannot be spaces in the expression because a space terminates the expression.