summaryrefslogtreecommitdiffstats
path: root/doc/groff.html.node/if_002delse.html
blob: 3c67fa93b53de82858225ed5e846b8991b1d4e00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.0.3, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- This manual documents GNU troff version 1.23.0.

Copyright � 1994-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License". -->
<title>if-else (The GNU Troff Manual)</title>

<meta name="description" content="if-else (The GNU Troff Manual)">
<meta name="keywords" content="if-else (The GNU Troff Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Request-Index.html" rel="index" title="Request Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Conditionals-and-Loops.html" rel="up" title="Conditionals and Loops">
<link href="while.html" rel="next" title="while">
<link href="Operators-in-Conditionals.html" rel="prev" title="Operators in Conditionals">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="if_002delse">
<div class="nav-panel">
<p>
Next: <a href="while.html" accesskey="n" rel="next">while</a>, Previous: <a href="Operators-in-Conditionals.html" accesskey="p" rel="prev">Operators in Conditionals</a>, Up: <a href="Conditionals-and-Loops.html" accesskey="u" rel="up">Conditionals and Loops</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Request-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="if_002delse-1">5.23.3 if-else</h4>
<a class="index-entry-id" id="index-if_002delse"></a>

<dl class="first-deffn">
<dt class="deffn" id="index-_002eie"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.ie</code></strong> <var class="def-var-arguments">cond-expr anything</var><a class="copiable-link" href='#index-_002eie'> &para;</a></span></dt>
<dd><a class="index-entry-id" id="index-ie"></a>
</dd><dt class="deffnx def-cmd-deffn" id="index-_002eel"><span class="category-def">Request: </span><span><strong class="def-name"><code class="t">.el</code></strong> <var class="def-var-arguments">anything</var><a class="copiable-link" href='#index-_002eel'> &para;</a></span></dt>
<dd><a class="index-entry-id" id="index-el"></a>
<p>Use the <code class="code">ie</code> and <code class="code">el</code> requests to write an if-then-else.  The
first request is the &ldquo;if&rdquo; part and the latter is the &ldquo;else&rdquo; part.
Unusually among programming languages, any number of non-conditional
requests may be interposed between the <code class="code">ie</code> branch and the
<code class="code">el</code> branch.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">.nr a 0
.ie \na a is non-zero.
.nr a +1
.el a was not positive but is now \na.
    &rArr; a was not positive but is now 1.
</pre></div></div>

<p>Another way in which <code class="code">el</code> is an ordinary request is that it does
not lexically &ldquo;bind&rdquo; more tightly to its <code class="code">ie</code> counterpart than it
does to any other request.  This fact can surprise C programmers.
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">.nr a 1
.nr z 0
.ie \nz \
.  ie \na a is true
.  el     a is false
.el z is false
    error&rarr; warning: unbalanced 'el' request
    &rArr; a is false
</pre></div></div>

<p>To conveniently nest conditionals, keep reading.
</p>
</dd></dl>


</div>



</body>
</html>