Flow-control structures: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: added an example of raising a condition (division by zero). -- ~~~~) |
m (→{{header|REXX}}: changed a REXX program example. -- ~~~~) |
||
Line 1,709: | Line 1,709: | ||
===leave=== |
===leave=== |
||
The '''leave''' statement transfer control to the next REXX statement following the '''end''' statment of the current '''do''' loop. The '''leave''' statement can also specify which '''do''' loop is to be left if the '''do''' loop has a named variable. |
The '''leave''' statement transfer control to the next REXX statement following the '''end''' statment of the current '''do''' loop. The '''leave''' statement can also specify which '''do''' loop is to be left if the '''do''' loop has a named variable. |
||
<lang rexx> |
<lang rexx></lang> |
||
say 'j=' j |
|||
if j>5 then leave |
|||
say 'negative j=' -j |
|||
end /*j*/ |
|||
say 'end of the DO loop for j.' |
|||
... |
|||
ouch=60 |
|||
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 /*m*/ |
|||
end /*k*/ |
|||
say 'sum=' sum</lang> |
|||
===raising conditions=== |
===raising conditions=== |
||
Line 1,839: | Line 1,822: | ||
(Also, see '''raising conditions''' above.) |
(Also, see '''raising conditions''' above.) |
||
<lang rexx> |
<lang rexx>... |
||
signal on error |
|||
signal on failure |
signal on failure |
||
signal on halt |
signal on halt |