• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Symbol Functions
      • Item Functions
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Case Object
      • Document Object
      • File Object
      • Freq Object
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
        • Break Statement
        • Do Statement
        • Exit Statement
        • For Statement
        • ForCase Statement
        • For (Dictionary) Statement
        • If Statement
        • Next Statement
        • Universe Statement
        • When Statement
        • While Statement
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Action Invoker
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataViewer>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

For Statement

Format
for ʃcounter inʅ multiple_occurring_group ʃwhere conditionʅ do
   
// statements
endfor;
Description
The for statement executes one or more statements repeatedly within a loop for each occurrence of a multiply occurring group. The multiple_occurring_group can be a form, roster, record, item, relation, or even a dictionary (following a selcase function call). The multiply occurring group controls how many times the for loop is executed. An optional logical condition, referencing items in the group, can be supplied to restrict the cases processed by the loop.
The numeric variable counter contains the number of the current occurrence being examined. It cannot be changed inside the loop, but it can be referenced. Its starting value is 1 and its ending value is determined by the number of occurrences of the group. It is possible to declare a variable local to the loop by adding numeric before the counter variable.
If the group name is a record, item, or relation, then the appropriate keyword Record, Item, or Relation can be used before the name.
The for statement should be coded outside of the group it references. In the example below, note that the code is executed in PROC QUEST. It should not be located in PROC PERSON_REC_EDT or in a procedure for any of the data items within the person record.
Example
PROC QUEST

   
numeric pointer_spouse;
   
numeric pointer_oldest_child;

   
for numeric occurrence_number in PERSON_REC_EDT do

       
if RELATIONSHIP = 2 then
            pointer_spouse = occurrence_number;

       
elseif RELATIONSHIP = 3 then
           
if pointer_oldest_child = 0 or AGE > AGE(pointer_oldest_child) then
                pointer_oldest_child = occurrence_number;
           
endif;

       
endif;

   
endfor;
See also: ForCase Statement, For (Dictionary) Statement, Do Statement, While Statement