Jump to content

Conditional structures: Difference between revisions

no edit summary
No edit summary
Line 355:
<lang befunge>& #v_ "0",@ zero
> "X",@ non-zero</lang>
 
=={{header|Bracmat}}==
=== "if .. then .. else .." type of branching ===
Bracmat uses & and | for branching. These binary operators are like && and || in C-like languages. Bracmat does not have the notion of Boolean variables, but marks all evaluated expressions as either succeeded or failed. If the left hand side of the & operator has succeeded, Bracmat goes on evaluating the right hand side. Only if both of left and right hand sides succeed, the expression tree headed by the & operator as a whole succeeds. Likewise, only if both of left and right hand sides of an expression tree headed by | fail, the expression tree as a whole fails. Evaluated expressions are just that: expressions. The following expression writes "That's what I thought." to your screen and evaluates to the expression "Right".
 
<lang bracmat> 2+2:5
& put$"Strange, must check that Bracmat interpreter."
& 0
| put$"That's what I thought."
& Right</lang>
 
=== switch-like branching ===
Use a patterns with alternations. Note that the match-expression (the tree headed by the : operator) evaluates to the left hand side of the : operator. In the following example, the resulting expression is a single node containing "4".
 
 
<lang bracmat> 2+2
: ( (<3|>5)
& put$"Not quite, must check that Bracmat interpreter."
| (3|5)
& put$"Not far off, but must check that Bracmat interpreter some day."
| ?
& put$"That's what I thought."
)
</lang>
 
=={{header|Brainf***}}==
483

edits

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