...
Defining a Subroutine
Panel |
---|
subroutine name
[script line 1]
...
[script line n]
endsub |
Invoking a Subroutine
Sequence of Defining / Invoking a Subroutine
...
For example, the following subroutine will function correctly:
Panel |
---|
subroutine test
echo "This is subroutine test"
echo "$(_halton)"
endsub
echo "This is main()"
callsub test |
However, this subroutine will fail:
...
echo "This is main()"
callsub test
subroutine test
echo "This is subroutine test"
echo "$(_halton)"
endsub
|
Nesting / Recursion of Subroutines
...
For example, the following illustrates subroutine nesting:
Panel |
---|
subroutine a
echo "Beginning subroutine A"
callsub b
echo "Ending subroutine A"
endsub
subroutine b
echo "Beginning subroutine B"
echo "Ending subroutine B"
endsub
callsub a |
Example
Panel |
---|
subroutine loop_increment
echo "inside loop_increment: $(LOOP)"
set LOOP=<$(LOOP) + 1>
endsub
echo "Starting Loop:"
set LOOP=0
if <$(LOOP) LT 1>
callsub loop_increment
end
if <$(LOOP) LT 2>
callsub loop_increment
end
if <$(LOOP) EQ 2>
callsub loop_increment
end
echo "Final Value of LOOP: $(LOOP)" |
Output
Panel |
---|
Starting Loop:
inside loop_increment: 0
inside loop_increment: 1
inside loop_increment: 2
Final Value of LOOP: 3 |