Conditional structures: Difference between revisions

added MDL
m (/* {{header|Perl 6}} * typo)
(added MDL)
Line 2,892:
! Do something else
ENDIF;</lang>
 
=={{header|MDL}}==
 
===COND===
 
This is the main conditional structure in MDL, equivalent to <code>cond</code> in other Lisp variants. <code>COND</code> may contain any number of clauses. The first element of each clause is evaluated, and if it's true, each following element in the clause is evaluated; otherwise control proceeds to the next clause, and so on. In any case, the return value is the result of the last evaluation performed.
 
An "else" part is traditionally implemented as a final clause whose first element is an atom, like <code>T</code>, since atoms always evaluate to themselves and are always true.
 
<lang MDL><COND (<==? .X 1> <PRINC "one">)
(<==? .X 2> <PRINC "two">)
(T <PRINC "something else">)></lang>
 
===AND and OR===
 
These short-circuiting boolean functions can also be used as simple conditionals.
 
<lang MDL>;"Negate X if its value is less than 0"
<AND <L? .X 0> <SET X <- .X>>>
 
;"Print a message unless the quiet flag is set"
<OR .QUIET? <PRINC "Finished">></lang>
 
=={{header|Metafont}}==
Anonymous user