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.

Legacy Commands and Functionscution of the loop. The FOR loop terminates when the user presses ENTER, which causesthe QUIT command to execute.FOR x=1:1 READ !,"Number: ",num QUIT: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: ",num QUIT:num="" DO Calc(num)Calc(a)The following example of the FOR variable=start:increment:end form shows a FOR loopwhere the WRITE command is never executed, since the first value of i (10) is already greaterthan the end value (1) minus the increment value (1).FOR i=10:1:1 WRITE iThe following example shows a FOR loop that executes the WRITE command 10 timesthen completes with i=10.FOR i=1:1:10 WRITE iThe following example shows a FOR loop that executes the WRITE command 10 timesthen completes with i=11.SET i=1FOR i=1:0:10 WRITE i,! SET i=i+1Using FOR with Multiple forparametersA single FOR command can contain both types of parameter syntax. The following is anexample of FOR with multiple forparameters. The first forparameter is the expr syntax. Thesecond forparameter is the start:increment:end syntax. The two forparameters are separatedby a comma. The first time through the FOR, <strong>Caché</strong> uses the expr syntax, and invokes theTest subroutine with x equal to the value of y. In the second (and subsequent) iterations,<strong>Caché</strong> uses the start:increment:end syntax. It sets x to 1, then 2, etc. On the final iteration,x=10.MainloopFOR x=y,1:1:10 DO TestTest750 <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!