Syntax
Makes declarations compulsory: every name the program writes to must be declared first, or the program does not compile.
OPTION EXPLICITGood to know
- It is off by default. It applies to the whole program, included files too, wherever the line stands.
- It stands alone on its line. Only a
'comment may follow it:OPTION EXPLICIT // noteandOPTION EXPLICIT ONare refused. - Names that must be declared: the target of an assignment, a FOR counter, the target of
INC,DECandREAD. The error readsOPTION EXPLICIT requires a declaration for variable: score. - Declarations:
GLOBAL,LOCALinside a FUNCTION,AS, a PureBasic suffix (speed.f = 1.5),DIM,NewList,NewMap, a FUNCTION parameter, aCATCHvariable. - It checks the names you write, not the names you read.
total = totl + 1still compiles, and stops the program when the line runs:totl is not defined.
Example
OPTION EXPLICITGLOBAL score = 0GLOBAL i = 0lives AS integer = 3DIM grid(2)FUNCTION Hit(damage) LOCAL rest = lives - damage lives = restENDFUNCTIONHit(1)FOR i = 0 TO 2 grid(i) = i * 10 score = score + grid(i)NEXTConsole(Str(lives) + " " + Str(score)) ' 2 30In the manual : Variables and types