Next: , Previous: , Up: Conditionals and Loops   [Contents][Index]


5.23.3 if-else

Request: .ie cond-expr anything
Request: .el anything

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. Unusually among programming languages, any number of non-conditional requests may be interposed between the ie branch and the el branch.

.nr a 0
.ie \na a is non-zero.
.nr a +1
.el a was not positive but is now \na.
    ⇒ a was not positive but is now 1.

Another way in which el is an ordinary request is that it does not lexically “bind” more tightly to its ie counterpart than it does to any other request. This fact can surprise C programmers.

.nr a 1
.nr z 0
.ie \nz \
.  ie \na a is true
.  el     a is false
.el z is false
    error→ warning: unbalanced 'el' request
    ⇒ a is false

To conveniently nest conditionals, keep reading.