Looping through a Database

<< Click to Display Table of Contents >>

Navigation:  Concordance Programming Fundamentals > Working with the Database >

Looping through a Database

Previous topics have discussed the two main looping structures: For Loops and While Loops. However, CPL supports a third structure that deals strictly with databases: the cycle-loop. A cycle-loop loops through the current Concordance query. If you performed a search prior to executing a CPL, that query will still be active unless you change the query using built-in functions. The following describes the cycle-loop syntax:

cycle(databaseHandle)

{

   CodeToRunOnEveryRecordInQuery();

}

Note the cycle statement looks very similar to a for- and while-loop. The cycle loop begins and ends with curly brackets, and has a body of instructions in between. The item in between the parentheses after the keyword, cycle, is the database handle.

For example, assume that you have already performed a search on your Concordance database, and therefore already have the results of a query. The following code will change the contents of the AUTHOR field in every record of your query to "John Smith".

main()

{

   cycle(db) 

   {

      db->AUTHOR = "John Smith";
   }

}