Phix processes your source file in one pass, starting at the first
line and proceeding through to the last line. When a procedure or function
definition is encountered, the routine is checked for syntax and converted
into an internal form, but no execution takes place. When a statement that
is outside of any routine is encountered, it is checked for syntax,
converted into an internal form and then immediately executed.
A common practice is to immediately initialize a global variable, just
after its declaration. If your
.ex file contains only
routine definitions, but no immediate execution statements, then nothing will
happen when you try to run it (other than syntax checking). You need to have
an immediate statement to call your main routine (see the
Example Program).
It is quite possible to have a source file with nothing but
immediate statements, for example you might want to use phix as a
simple calculator, typing in just one
print
(or
?) statement into a file, and then executing it.
As we have seen, you can use any phix
statement, including
for-loops,
while-loops,
if statements etc. (but not
return), at the top level i.e.
outside
of any
or
procedure.
In addition, the following special statements may
only
appear at the top level:
- include
- with / without
- format