Conditional structures: Difference between revisions
Content added Content deleted
(→switch) |
(Added PicoLisp) |
||
Line 1,436: | Line 1,436: | ||
* [http://www.php.net/manual/en/language.control-structures.php php.net:Control Structures] |
* [http://www.php.net/manual/en/language.control-structures.php php.net:Control Structures] |
||
* [http://www.php.net/manual/en/control-structures.switch.php php.net:Control Structures: Switch] |
* [http://www.php.net/manual/en/control-structures.switch.php php.net:Control Structures: Switch] |
||
=={{header|PicoLisp}}== |
|||
===Two-way conditions=== |
|||
<lang PicoLisp>(if (condition) # If the condition evaluates to non-NIL |
|||
(then-do-this) # Then execute the following expression |
|||
(else-do-that) # Else execute all other expressions |
|||
(and-more) ) |
|||
(ifn (condition) # If the condition evaluates to NIL |
|||
(then-do-this) # Then execute the following expression |
|||
(else-do-that) # Else execute all other expressions |
|||
(and-more) )</lang> |
|||
One-way conditions |
|||
<lang PicoLisp>(when (condition) # If the condition evaluates to non-NIL |
|||
(then-do-this) # Then execute tall following expressions |
|||
(and-more) ) |
|||
(unless (condition) # If the condition evaluates to NIL |
|||
(then-do-this) # Then execute all following expressions |
|||
(and-more) )</lang> |
|||
===Four-way condition=== |
|||
<lang PicoLisp>(if2 (condition1) (condition2) # If both conditions evaluate to non-NIL |
|||
(expression-both) # Then execute this expression |
|||
(expression-first) # Otherwise this for the first |
|||
(expression-second) # or this the second condition. |
|||
(expression-none) # If both are NIL, all following expressions |
|||
(and-more) )</lang> |
|||
===Multiple conditions=== |
|||
<lang PicoLisp>(cond |
|||
((condition1) # If this condition evaluates to non-NIL |
|||
(expression 1) # Execute these expression(s) |
|||
(more 1) ) |
|||
((condition2) # Otherwise, if this evaluates to non-NIL |
|||
(expression 2) # Execute these expression(s) |
|||
(more 2) ) |
|||
... # ... |
|||
(T # If none evaluated to non-NIL |
|||
(expression 1) # Execute these expression(s) |
|||
(more 1) ) |
|||
(nond |
|||
((condition1) # If this condition evaluates to NIL |
|||
(expression 1) # Execute these expression(s) |
|||
(more 1) ) |
|||
((condition2) # Otherwise, if this evaluates to NIL |
|||
(expression 2) # Execute these expression(s) |
|||
(more 2) ) |
|||
... # ... |
|||
(NIL # If none evaluated to NIL |
|||
(expression 1) # Execute these expression(s) |
|||
(more 1) )</lang> |
|||
===Selection=== |
|||
<lang PicoLisp>(case (expression) # Evaluate the expression |
|||
(value1 # If it is equal to, or member of, 'value1' |
|||
(do-this1) # Execute these expression(s) |
|||
(do-that1) ) |
|||
(value2 # Else if it is equal to, or member of, 'value2 |
|||
(do-this2) # Execute these expression(s) |
|||
(do-that2) ) |
|||
... # ... |
|||
(T # Else execute final expression(s) |
|||
(do-something-else) ) )</lang> |
|||
=={{header|Pop11}}== |
=={{header|Pop11}}== |