MAIN
 
Syntax

MAIN:
Description


Normally an ARMbasic program will start at the first statement in the BASIC source.  This can be changed by having a MAIN: somewhere else in the program.  When a MAIN: does exist, the program will begin at this point.

MAIN: is useful for programs that use FUNCTIONs or SUBs and have those FUNCTIONs or SUBs at the beginning of the source.  This also includes FUNCTIONs or SUBs that are #include'd in the source.

Statements before the MAIN will not be executed, unless they are called or GOTO'd.  But those statements can be used to define variables or SUB.  The compiler attempts to show errors on code that it assumes is unreachable (since version 9.40).

A MAIN is not required in a program, but the compiler assumes that there will be one.  To get around that you can have a label at the start of the program and execution will begin there.

Example

SUB SUB1:
  PRINT "Hello from sub1"
END SUB

MAIN:
GOSUB SUB1
END
'or another example:

X = 1234     '  this defines X as an INTEGER variable without using a DIM

MAIN:

PRINT x   ' will print 0, because while X is defined the assignment of 1234 never happened

Differences from other BASICs

See also