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.

<strong>Caché</strong> <strong>ObjectScript</strong> CommandsUsing 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.MainloopSET y="beta"FOR x=y,1:1:10 {DO Test}QUITTestWRITE !,"Running test number ",xQUITIncrementing with Argumentless FORThe argumentless FOR operates the same as the FOR variable=start:increment form. Theonly difference is that it does not provide a way to keep track of the number of loop executions.The following example shows how the previous loop counter example might be rewrittenusing the argumentless FOR. The assignment i=i+1 replaces the loop counter.Average2loopSET sum=0SET i=0FOR {READ !,"Number: ",num QUIT:num=""SET sum=sum+num,i=i+1}SET average=sum/iWRITE !!,"Average is: ",averageQUITNotesFOR and WatchpointsYou have limited use of watchpoints with FOR. If you establish a watchpoint for the control(index) variable of a FOR command, <strong>Caché</strong> triggers the specific watchpoint action only onthe initial evaluation of each FOR command argument. This restriction is motivated by performanceconsiderations.The following example contains three kinds of FOR command arguments for the watchedvariable x: a range, with initial value, increment, and limit (final value); a single value; and44 <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!