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.

cution of the loop. The FOR loop terminates when the user presses ENTER, which causesthe QUIT command to execute.MainloopFOR x=1:1 {READ !,"Number: ",numQUIT:num=""DO Calc(num,x)}Calc(a,b)The following example of the FOR variable=start:increment:end form prompts the user fora number and then passes the number to the Calc subroutine invoked by DO. The value of xis initialized to 1 and is incremented by 1 for each execution of the loop. The FOR loop terminateseither when the value of x would exceed the end value (3) or when the user pressesENTER, causing the QUIT command to execute.MainloopFOR x=1:1:3 {READ !,"Number: ",numQUIT:num=""DO Calc(num)}Calc(a)The following example of the FOR variable=start:increment:end form shows a FOR loopwhich is never executed, since the first value of i (10) is already greater than the end value(1) minus the increment value (1).WRITE !,"Before the FOR"FOR i=10:1:1 {WRITE !,"In the FOR loop, i=",i}WRITE !,"After the FOR"The following example shows a FOR loop that executes the WRITE command 10 times,then completes with i=10.Writeloop1FOR i=1:1:10 {WRITE i,!}WRITE "i=",iQUITThe following example shows a FOR loop that executes the WRITE command 10 times,then completes with i=11.Writeloop2FOR i=1:0:10 {WRITE i,!SET i=i+1}WRITE "i=",iQUITFOR<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 43

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

Saved successfully!

Ooh no, something went wrong!