Conditional structures: Difference between revisions

Content added Content deleted
Line 2,005: Line 2,005:
disp("unknown!");
disp("unknown!");
endswitch</lang>
endswitch</lang>


=={{header|ooRexx}}==
For all of the conditional instructions, the conditional expression must evaluate either to '1' or '0'. Note that ooRexx conditional
expression evaluation does not have a short circuiting mechanism. Where the logical operations | (or), & (and), or && (exclusive or) are
used, all parts of the expression are evaluated.
The conditional
may also be a list of conditional expressions separated by commas. The expressions are evaluated left-to-right, and evaluation
will stop with the first '0' result. For example,

would fail with a syntax error if the variable arg does not hold a string because the right-hand-side of the expression
is still evaluated. This can be coded as

<lang ooRexx>
if arg~isa(.string), arg~left(1) == "*" then call processArg arg
</lang>
With this form, the second conditional expression is only evaluated if the first expression is true.

===IF THEN --- IF THEN/ELSE===
<lang ooRexx>
if y then x=6 /* Y must be either 0 or 1 */


if t**2>u then x=y
else x=-y



if t**2>u then do j=1 to 10; say prime(j); end
else x=-y



if z>w+4 then do
z=abs(z)
say 'z='z
end
else do; z=0; say 'failed.'; end



if x>y & c*d<sqrt(pz) |,
substr(abc,4,1)=='@' then if z=0 then call punt
else nop
else if z<0 then z=-y
</lang>

===SELECT WHEN===
<lang ooRexx>
/*the WHEN conditional operators are the same as */
/*the IF conditional operators. */

select
when t<0 then z=abs(u)
when t=0 & y=0 then z=0
when t>0 then do
y=sqrt(z)
z=u**2
end

/*if control reaches this point and none of the WHENs */
/*were satisfiied, a SYNTAX condition is raised (error).*/
end
</lang>
===SELECT WHEN/OTHERWISE===
<lang ooRexx>
select
when a=='angel' then many='host'
when a=='ass' | a=='donkey' then many='pace'
when a=='crocodile' then many='bask'
when a=='crow' then many='murder'
when a=='lark' then many='ascension'
when a=='quail' then many='bevy'
when a=='wolf' then many='pack'
otherwise say
say '*** error! ***'
say a "isn't one of the known thingys."
say
exit 13
end
</lang>


=={{header|Oz}}==
=={{header|Oz}}==