12.07.2015 Views

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

ILOG OPL Development Studio Language Reference Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Outside a function definitionAt the same level as function definitions, script variables declared with var are local to thecurrent program unit. A program unit is a group of statements which is considered a whole;the exact definition of a program unit depends on the application in which the script isembedded. Typically, a script file loaded by the application is treated as a program unit. Inthis case, variables declared with var at the file top level are local to this file, and they hideany global variables with the same names.For example, suppose that a file contains the following program:var count = 0function NextNumber() {count = count+1return count}When this file is loaded, the function NextNumber becomes visible to the whole application,while count remains local to the loaded program unit and is visible only inside it.It is an error to declare the same local variable twice in the same scope. For example, thefollowing program is incorrect because res is declared twice:function max(x, y) {if (x > y) {var res = x} else {var res = y // Error}return res}I L O G O P L D E V E L O P M E N T S T U D I O L A N G U A G ER E F E R E N C E M A N U A L201

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!