Anonymous user
Flow-control structures: Difference between revisions
m
→{{header|REXX}}: remove first and last blank lines from program examples. -- ~~~~
DavidWhitten (talk | contribs) |
m (→{{header|REXX}}: remove first and last blank lines from program examples. -- ~~~~) |
||
Line 1,296:
<br> Some operating systems require the expression to be a whole number (often with a
<br> no expression or a [null] expression is usually taken to mean a return code of 0).
<lang rexx>exit
exit expression</lang>
===return===
the RETURN statement terminates the running (REXX) program and passes control to
Line 1,310 ⟶ 1,308:
<br> results in an abnormal termination of the invoking REXX program (this condition can be
<br> trapped, however).
<lang rexx>return
return expression</lang>
===signal===
The SIGNAL statement can be thought of as a GO TO statement, however, on issuance of
Line 1,336 ⟶ 1,332:
<br> ∙ when a command executed returns an error return code [other than 0 (zero)].
<br> ∙ when a command executed indicates a failure.
<lang rexx>signal on error
signal on failure
signal on halt
Line 1,344 ⟶ 1,339:
signal on novalue
signal on syntax
signal off error
Line 1,353 ⟶ 1,347:
signal off novalue
signal off syntax
∙
∙
Line 1,377 ⟶ 1,370:
∙
∙
∙</lang>
===leave===
Line 1,385 ⟶ 1,377:
<br> The LEAVE statement can also specify which DO loop is to be left if the DO loop has
<br> a named variable.
<lang rexx> do j=1 to 10
say 'j=' j
if j>5 then leave
say 'negative j=' -j
end
Line 1,398 ⟶ 1,389:
sum=0
do k=0 to 100 by 3
say 'k=' k
do m=1 to k
if m=ouch then leave k
sum=sum+m
end
end
say 'sum=' sum</lang>
===iterate===
The ITERATE statement immediately transfer control to the DO statement, that is, it iterates
<br> (increments or decements) the named REXX variable that is specified on the DO statement.
<br> The ITERATE statement can also specify which DO loop is to be iterated.
<lang rexx>sum=0
do j=1 to 1000
if j//3==0 | j//7==0 then iterate
sum=sum+j
end
Line 1,429 ⟶ 1,418:
prod=0
do k=1 to 2000
do m=1 to k
if m>99 then iterate k
prod=prod*m
end
end
say 'prod=' prod</lang>
===call===
The CALL statement immediately transfer control to a named subroutine, and the CALL
<br> statement may have any number (or none) parameters.
<br> The named subroutine may or may not return a RESULT (which is similar to a return code).
<lang rexx>numeric digits 1000 /*prepare for some gihugeic numbers.*/▼
▲numeric digits 1000 /*prepare for some gihugeic numbers.*/
∙
∙
Line 1,457 ⟶ 1,444:
!=1
do j=2 to x
!=!*j
end
return !</lang>
===select===
The SELECT statement is used to conditionaly test for cases to selectively execute REXX
<br> statement(s).
<lang rexx> ∙
∙
∙
Line 1,478 ⟶ 1,463:
∙
∙
select
when op=='+' then r=a+b /*add. */
Line 1,492 ⟶ 1,476:
end
say 'result for' a op b "=" r</lang>
=={{header|Ruby}}==
|