Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Macro name changed from html to html-bobswift during server to cloud migration processing.

...

Defining a Subroutine

Panel

Html bobswift

<pre>
subroutine name
[script line 1]
...
[script line n]
endsub
</pre>

Invoking a Subroutine

Panel

Html bobswift

<pre>
callsub name
</pre>

Sequence of Defining / Invoking a Subroutine

...

For example, the following subroutine will function correctly:

Panel

Html bobswift

<pre>
subroutine test
   echo "This is subroutine test"
   echo "$(_halton)"
endsub

echo "This is main()"
callsub test
</pre>


However, this subroutine will fail:

Panel

Html bobswift

<pre>
echo "This is main()"
callsub test

subroutine test
   echo "This is subroutine test"
   echo "$(_halton)"
endsub
</pre>

 

Nesting / Recursion of Subroutines

...

For example, the following illustrates subroutine nesting:

Panel

Html bobswift

<pre>
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
</pre>

Example

Panel

Html bobswift

<pre>
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)"
</pre>

Output

Panel

Html bobswift

<pre>
Starting Loop:
inside loop_increment: 0
inside loop_increment: 1
inside loop_increment: 2
Final Value of LOOP: 3
</pre>