Amos Professional Manual  Contents  Index

Procedures


The POP PROC instruction provides you with a fast getaway, if you ever find yourself in need of escape. Try this:

E> ESCAPE
   Procedure ESCAPE
    For PRISON=1 To 1000000000
     If PRISON=10 Then Pop Proc
     Print "I am abandoned."
    Next PRISON
   End Proc
   Print "I'm free!"

ON BREAK PROC
structure: jump to a procedure when break in program
On Break Proc NAME

A jump can also be made to a specified procedure when the program is interrupted. For example:

E> On Break Proc BROKEN
   Do
    Print "Unbroken" : Wait 50
   Loop
   Procedure BROKEN
    Print "I am the procedure"
   End Proc

Local and global variables
All of the variables that are defined inside a procedure work completely separately from any other variables in your programs. We call these variables "local" to the procedure. All local variables are automatically discarded after the procedure has finished executing, so that in the following example the same value of 1 will always be printed, no matter how many times it is called:

X> Procedure PLUS
    A=A+1 : Print A
   End Proc

All the variables OUTSIDE of procedures are known as "global" variables, and they are not affected by any instructions inside a procedure. So it is perfectly possible to have the same variable name referring to different variables, depending on whether or not they are local or global.

When the next example is run, it can be seen that the values given to the global variables are different to those of the local variables, even though they have the same name.

Back    Next
05.05.04