Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using the Mod function to test the iteration in a loop
Published On: May 21, 1999
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

When writing code for an operation such as printing, it is sometimes desirable to perform an action every number off iterations. For example, if a 15 records are being printed using Print Form, there might be only room for 3 records per page.
There is a simple way of testing to see if a record is the 3rd record on a page using the "Mod" function. The Mod function returns the remainder of the Integer division of a number by another number. So if 7 is divided by 3 equals an integer of 2, the Mod is 1. Mod can be thought of as the remainder. To make Mod work in a loop, just divide the number being tested by the desired iteration.
The example code will print 5 pages with 3 records per page.