11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The Argumentless DO CommandThe argumentless DO command executes a block of code that immediately follows it in thesame program. Argumentless DO blocks can be nested, and a postconditional expression onthe DO command can be used to determine whether or not to execute a code block.The block structures provided by the IF, FOR, DO WHILE, and WHILE commands are apreferable means to perform the same operations. The argumentless DO command continuesto be supported, but its use in new coding is discouraged. For further details, see ArgumentlessDO (legacy version).The DO Command with ArgumentsThe DO command with entryref arguments invokes the execution of one or more blocks ofcode that are defined elsewhere. Each block of code to execute is specified by its entryref.The DO command can specify multiple blocks of code to execute as a comma-separated list.The execution of the DO command, and the execution of each entryref in a comma-separatedlist can be governed by optional postconditional expressions.DO can invoke the execution of a subroutine (with or without parameter passing), a procedure,or an extrinsic function. Upon completion of the execution of the block of code, executionresumes at the next command after the DO command. A block of code invoked by the DOcommand cannot return a value to the DO command. Thus DO can execute an extrinsicfunction, but cannot receive the return value of that function.You can specify a $CASE function as a DO command argument.The DO Command without Parameter PassingThe DO command without parameter passing is only used with subroutines. Use of DOentryref without parameter passing (that is, without specifying the param option) takesadvantage of the fact that a calling routine and its called subroutine share the same variableenvironment. Any variable updates made by the subroutine are automatically available to thecode following the DO command.When using DO without parameter passing, you must make sure that both the calling routineand the called subroutine reference the same variables.DONote:Procedures handle variables entirely differently. Refer to Procedures in Using <strong>Caché</strong><strong>ObjectScript</strong>.In the following example, Start (the calling routine) and Exponent (the called subroutine)share access to three variables: num, powr, and result. Start sets num and powr to the usersuppliedvalues. These values are automatically available to Exponent when it is called by<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 27

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

Saved successfully!

Ooh no, something went wrong!