Scope/Function names and labels: Difference between revisions

Content added Content deleted
m (added whitespace before the TOC, added a Task (bold) header.)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.)
Line 462: Line 462:
<br>(all of the above are normally contained on one line (record), but may (syntactically) be continued by the normal REXX rules for continuation.
<br>(all of the above are normally contained on one line (record), but may (syntactically) be continued by the normal REXX rules for continuation.
<br><br>Any label can be referenced from anywhere in the REXX program &nbsp; (global scope).
<br><br>Any label can be referenced from anywhere in the REXX program &nbsp; (global scope).
<br><br>Multiple labels (with the same name) are not considered an error in the REXX language; &nbsp; the first label found is used.
<br><br>Multiple labels (with the same name) are not considered an error in the REXX language; &nbsp; the first label found (topmost) is used.
<lang rexx>/*REXX program demonstrates use of labels and a CALL statement. */
<lang rexx>/*REXX program demonstrates the use of labels and also a CALL statement. */
blarney = -0 /*just a blarney & balderdash statement*/
zz=4
signal do_add /*transfer program control to a label.*/
signal do_add /*transfer program control to a label.*/
ttt=sinD(30) /*this REXX statement is never executed.*/
ttt = sinD(30) /*this REXX statement is never executed*/
/* [↓] Note the case doesn't matter. */
/* [↓] Note the case doesn't matter. */
do_Add: /*coming here from the SIGNAL statement.*/
DO_Add: /*coming here from the SIGNAL statement*/


say 'calling the sub: add.2.args'
say 'calling the sub: add.2.args'
call add.2.args 1,7 /*pass two arguments: 1 and a 7 */
call add.2.args 1, 7 /*pass two arguments: 1 and a 7 */
say 'sum =' result /*display the result from the function.*/
say 'sum =' result
exit /*stick a fork in it, 'cause we're done.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*────────────────────────────────subroutines (or functions)────────────*/
add.2.args: procedure; parse arg x,y; return x+y
add.2.args: procedure; parse arg x,y; return x+y /*first come, first served ···*/
add.2.args: say 'Whoa Nelly!! Has the universe run amok?' /*didactic, but never executed*/

add.2.args: return arg(1) + arg(2) /*concise, " " " */</lang>
add.2.args: say 'Whoa Nelly!! Has the universe run amok?'
/* [↑] dead code, never XEQed*/
add.2.args: return arg(1) + arg(2) /*concise, but never executed.*/</lang>
'''output'''
'''output'''
<pre>
<pre>