Conditional structures: Difference between revisions

Line 2,928:
In the shortened forms, you dispense with the keywords (except the first one).
 
===if/else if/elseexpressions===
If expressions are scoped per section.
<lang Langur># using the fact that submatch() returns an empty array for no match and that a decoupling assignment returns a Boolean...
# ... and that a decoupling assignment returns a Boolean...
 
if val (.alias, .name) = submatch($re/^(\.idregex;)\\s*;\\s*(\.idregex;)/, .row) {
Line 2,948 ⟶ 2,949:
<lang Langur>if(.x > .y: ...; .x < .y: ...; /* else */ ...)</lang>
 
===given expressions===
Given expressions are highly flexible. See langurlang.org for details.
 
Given expressions are scoped per block. Also, test expressions (the .x, .y, .z list below) may contain declarations which are scoped to the entire expression. Conditions (case statements) may not contain declarations.
 
<lang Langur>given .x, .y, .z {
case true: ... # all are true
Line 2,957 ⟶ 2,959:
case _, null, true: ... # .y == null and .z == true
}</lang>
 
The default logical operator between multiple conditions is "and" (even when there is a single test expression). You can specify another operator after the "case" keyword, using something like "case or".
 
<lang Langur>given .x, .y, != .z {
1,006

edits