Conditional structures: Difference between revisions
Content added Content deleted
m (copy edit - wiki link to wikipedia) |
(adding MUMPS information) |
||
Line 1,284: | Line 1,284: | ||
IO.Put("Something\n"); |
IO.Put("Something\n"); |
||
END;</lang> |
END;</lang> |
||
=={{header|MUMPS}}== |
|||
===If / I=== |
|||
<lang MUMPS> IF A GOTO Label</lang> |
|||
<p>Some versions of MUMPS do allow an ELSE statement, which can be abbreviated to E. Instead of looking at the previous IF statment, |
|||
it looks at the value of the system variable $TEST. $TEST is set whenever a conditional statement is executed, thus could be set without the |
|||
programmer realizing it. For example: |
|||
<lang MUMPS> IF T DO SUBROUTINE |
|||
ELSE DO SOMETHING</lang> |
|||
isn't clear because the function SUBROUTINE might change the value of $TEST. |
|||
</p> |
|||
===$Select / $S=== |
|||
<lang MUMPS> WRITE $SELECT(1=2:"Unequal",1=3:"More unequal",1:"Who cares?")</lang> |
|||
<p>The $Select statement contains couplets consisting of a conditional test, followed by a colon, and what to return if that condition is true. |
|||
The couplets are separated by commas. Nonzero numbers evaluate as true. Typically an explicitly true condition is placed in the final |
|||
couplet. If no conditions are true, an error is returned and the program aborts.</p> |
|||
===:=== |
|||
<lang MUMPS> SET:(1=1) SKY="Blue" |
|||
GOTO:ReallyGo LABEL |
|||
QUIT:LoopDone |
|||
WRITE:NotLastInSet ","</lang> |
|||
<p>Most commands can take a "postconditional", which is a colon and some conditional statement immediately after the command followed by a space and the usual arguments of the command. The command is executed only if the conditional statement evaluates to true.</p> |
|||
<p>The exceptions are FOR, IF, ELSE, and READ. For the Read command, a number (or numeric expression) after a colon is the number of seconds to wait for a user to make an entry before throwing an error.</p> |
|||
=={{header|newLISP}}== |
=={{header|newLISP}}== |