Conditional structures: Difference between revisions
→{{header|langur}}
Langurmonkey (talk | contribs) |
|||
Line 3,893:
=={{header|langur}}==
If and switch
In the shortened forms, you dispense with the keywords (except the first one).
Line 3,917:
===simple if===
<syntaxhighlight lang="langur">if .x > .y: break</syntaxhighlight>
===switch
Switch
Switch
<syntaxhighlight lang="langur">switch .x, .y, .z {
Line 3,943:
}
case true: ...
# all are true
Line 3,952:
}</syntaxhighlight>
===implicit fallthrough===
If a block of a switch
<syntaxhighlight lang="langur">
case true:
# implicit fallthrough
Line 3,965:
===explicit fallthrough from anywhere===
A fallthrough statement is allowed anywhere within a switch
<syntaxhighlight lang="langur">
case true:
if .y > 100 {
Line 3,976 ⟶ 3,977:
}</syntaxhighlight>
===shortened form switch
A shortened form expects a single action expression per test and is more limited in other ways, as well (no explicit fallthrough, no alternate test expressions, no alternate logical operators). A default section is optional (null by default).
<syntaxhighlight lang="langur">
true: ... ; #
_, >= .z: ...; # .y >= .z
... ) # default</syntaxhighlight>
|