Jump to content

Conditional structures: Difference between revisions

→‎{{header|Langur}}: add fallthrough explanations
(→‎{{header|Langur}}: add fallthrough explanations)
Line 2,949:
case _, _, == 7; xor .a <= .b: ... # .z == 7 xor .a <= .b
default: ...
}</lang>
 
===implicit fallthrough===
If a block of a given has any statements, there is no implicit fallthrough. A case with an empty block after it creates an implicit fallthrough.
<lang Langur>given .x {
case true: # implicit fallthrough
case null: 0 # no fallthrough
default: 1
}</lang>
 
===fallthrough from anywhere===
A fallthrough statement is allowed anywhere within a given block, not just at the end.
<lang Langur>given .x {
case true:
if .y > 100 {
fallthrough
} else {
120
}
case false: ...
}</lang>
 
===shortened form given===
The shortened form expects a single expression per test and is also more limited (no explicit fallthrough, no alternate test expressions, no alternate logical operators).
<lang Langur>given(.x, .y, .z; true: /* all true */ ... ; _, >= .z: /* .y >= .z */ ...; /* default */ ... )</lang>
 
1,006

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.