aboutsummaryrefslogtreecommitdiff
path: root/pkg/language/doc/if.hlp
blob: eac7686f56b92dc98076b07f71fe972e4dac5709 (plain) (blame)
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
.help "if,else" Feb86 language
.ih
NAME
if else -- conditional execution of a statement
.ih
SYNTAX
\fIif\fR (expression) statement1 [\fIelse\fR statement2]
.ih
ELEMENTS
.ls expression
A boolean valued expression.
.le
.ls statement1, statement2
The statements to be executed (possibly compound, i.e., enclosed in
curly braces).
.le
.ih
DESCRIPTION
The \fIif\fR statement is used to execute a statement only if the
specified condition is true.  An optional \fIelse\fR clause may be given
to execute a different statement if the condition is false.
.ih
EXAMPLES
1. Add X to Y only if X is less than Y.

.nf
	if (x < y)
	    y += x
.fi

2. If X is less than 10 print "small", else print "big".

.nf
	if (x < 10)
	    print ("small")
	else
	    print ("big")
.fi

3. The \fIelse if\fR construct.

.nf
	if (str == "+")
	    val += x
	else if (str == "-")
	    val -= x
	else if
	    ...
.fi

4. Nesting, use of braces.

.nf
	if (i > 0) {
	    if (i < 10) {
		print ("0")
		sum = sum * 10 + i
	    } else
		print (" ")
	}
.fi
.ih
SEE ALSO
for, case, break, next
.endhelp