Nested function: Difference between revisions
Content added Content deleted
m (→using a class: added phix/class) |
m (→{{header|REXX}}: added/changed whitespace and comments.) |
||
Line 1,148: | Line 1,148: | ||
This REXX version is modeled after the '''FreeBASIC''' example (and it has the |
This REXX version is modeled after the '''FreeBASIC''' example (and it has the |
||
same limitations). |
same limitations). |
||
<lang rexx>/*REXX program |
<lang rexx>/*REXX program demonstrates that functions can be nested (an outer and inner function).*/ |
||
ctr= |
ctr= 0 /*initialize the CTR REXX variable.*/ |
||
call makeList '. ' /*invoke |
call makeList '. ' /*invoke makeList with the separator.*/ |
||
exit |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
makeItem: parse arg sep,text; ctr=ctr+ |
makeItem: parse arg sep,text; ctr= ctr + 1 /*bump the counter variable. */ |
||
say ctr || sep || word(string, ctr) |
say ctr || sep || word(string, ctr) /*display three thingys to the terminal*/ |
||
return |
return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
makeList: parse arg sep; string= 'first second third' /*get arguments; define a |
makeList: parse arg sep; string= 'first second third' /*get arguments; define a strong.*/ |
||
do while ctr<3 |
do while ctr<3 /*keep truckin' until finished.*/ |
||
call makeItem sep, string |
call makeItem sep, string /*invoke the makeItem function.*/ |
||
end /*while*/ |
end /*while*/ |
||
return</lang> |
return</lang> |
||
{{out|output|text= when using the default input:}} |
|||
'''output''' |
|||
<pre> |
<pre> |
||
1. first |
1. first |