11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

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.

Legacy Commands and Functionsto the WRITE command through the same shared local variable. The first block (which calculatesthe square of an integer) contains an implicit QUIT while the second block (whichcalculates the cube of an integer) contains an explicit QUIT.Start ; Square or cube an integer.READ !,"Square (S) or cube (C): ",op QUIT:op=""READ !,"Integer: ",num QUIT:num=""IF (op["S")!(op["s") DO. SET result=num*num ; Square block. WRITE !,"Result: ",resultELSE DO. SET result=num*num*num ; Cube block. WRITE !,"Result: ",result. QUITGOTO StartIn the following example, the argumentless DO repeatedly executes the code block until theFOR control variable (i) equals the value of y.FOR i=1:1:y DO. SET z=z*x. WRITE !,z. QUITThe following example shows nested code blocks in <strong>Caché</strong> <strong>ObjectScript</strong>, using implicit QUITcommands to end each block.MyRoutine ; Routine labelWRITE !,"At top level" ; Mainline code (Level count = 0)DO. ; Outermost block (Level count = 1).. DO. . ; Inner block 1 (Level count = 2). .. . DO. . . ; Inner block 2 (Level count = 3). . .. . ; (Level count = 2). ; (Level count = 1).. QUIT ; (Level count = 0)WRITE !,"Back at top level" ; Mainline code resumesAs shown in the preceding example, the first argumentless DO begins execution of the linesin the outermost block of code. <strong>Caché</strong> <strong>ObjectScript</strong> saves the line level at which the DOresides. If <strong>Caché</strong> <strong>ObjectScript</strong> encounters subsequent argumentless DO commands, it executesthe next inner block of code and increments the line level by one for each such command.When it finds an implicit or explicit QUIT in a block, <strong>Caché</strong> <strong>ObjectScript</strong> decrements theline level count by one and continues execution at the command that follows the DO for thatblock.744 <strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong>

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

Saved successfully!

Ooh no, something went wrong!