Debian Codegraph @

doc/antora/modules/unlang/pages/elsif.adoc

raw
1 = The elsif Statement
2
3 .Syntax
4 [source,unlang]
5 ----
6 if (condition-1) {
7 [ statements-1 ]
8 }
9 elsif (condition-2) {
10 [ statements-2 ]
11 }
12 else {
13 [ statements-3 ]
14 }
15 ----
16
17 An `elsif` statement is used to evaluate a subsequent
18 xref:condition/index.adoc[condition] after a preceding xref:if.adoc[if] statement
19 evaluates to `false`. In the example above, when _condition-1_
20 evaluates to false, then _statements-1_ are skipped and _condition-2_
21 is checked. When _condition-2_ evaluates true, then _statements-2_
22 are executed. When _condition-2_ evaluates false, then
23 _statements-2_ are skipped and _statements-3_ are executed.
24
25 As with xref:if.adoc[if], an `elsif` clause does not need to be followed by
26 an xref:else.adoc[else] statement. However, any xref:else.adoc[else] statement
27 must be the last statement in an `elsif` chain. An arbitrary number of
28 `elsif` statements can be chained together to create a series of
29 conditional checks and statements.
30
31 .Example
32 [source,unlang]
33 ----
34 if (&User-Name == "bob") {
35 reject
36 }
37 elsif (&User-Name == "doug") {
38 ok
39 }
40 ----
41
42 // Copyright (C) 2020 Network RADIUS SAS. Licenced under CC-by-NC 4.0.
43 // Development of this documentation was sponsored by Network RADIUS SAS.