Next: while, Previous: Operators in Conditionals, Up: Conditionals and Loops [Contents][Index]
gtroff
has if-then-else constructs like other languages, although
the formatting can be painful.
Evaluate the expression expr, and executes anything (the remainder of the line) if expr evaluates to a value greater than zero (true). anything is interpreted as though it was on a line by itself (except that leading spaces are swallowed). See Operators in Conditionals, for more info.
.nr xxx 1 .nr yyy 2 .if ((\n[xxx] == 1) & (\n[yyy] == 2)) true ⇒ true
Executes anything. This is similar to .if 1
.
Use the ie
and el
requests to write an if-then-else. The
first request is the ‘if’ part and the latter is the ‘else’ part.
.ie n .ls 2 \" double-spacing in nroff .el .ls 1 \" single-spacing in troff
In many cases, an if (or if-else) construct needs to execute more than
one request. This can be done using the escapes \{
(which must
start the first line) and \}
(which must end the last line).
.ie t \{\ . ds lq `` . ds rq '' .\} .el \{\ . ds lq "" . ds rq "" .\}
See Expressions.