2 Replies Latest reply on Nov 25, 2011 11:57 AM by RayCologon

    Better looping structure?

    ghoffman

      Following programming practices of experts, I've built several solutions that included scripts with looping structures similar to this:

       

      Setup steps (Go to layout, Freeze Window, etc.)

      Perform Find

      Go to Record/Request/Page [First]

      Do some operations

      Loop

      Go to Record/Request/Page [Next; Exit after Last]

      Do some operations

      End Loop

       

      Sometimes the operations line will be many lines long and has to be repeated inside the loop.

       

      However, I have recently begun to use a different structure, as follows:

       

      Setup steps

      Perform Find

      Go to Record/Request/Page [First]

      Loop

      Do some operations

      Go to Record/Request/Page [Next; Exit after Last]

      End Loop

       

      Using this structure, if I have to change the operations lines, I don't have to do it in two places.

       

      So I ask you, is there something inherently wrong with this second structure? If not, why do the experts continue to use the first?

       

      Just askin'

       

      Gary

        • 1. Re: Better looping structure?
          John Funk

          I have used both but the main difference is if you need to set ot get data on the first record or not. If you are looping through records your initial variables will get wriiten over.

          John

          • 2. Re: Better looping structure?
            RayCologon

            Hi Gary,

             

            The second script formation is not inherently wrong, and in most cases is preferable.

             

            Reasons why a developer, whether expert or not, might use the first structure would include:

             

            1. That they needed for some reason to process the first record differently from the others in some way,
            2. That the second method had not yet occurred to them, or
            3. Some other 'expert' told them to do it that way and they've never questioned it.

             

            I'm sure we've all been guilty of making things more complicated than they need to be at one time or another. As you've shown, the most obvious way isn't necessarily the most efficient or expedient.

             

            Regards,

            Ray

            ------------------------------------------------

            R J Cologon, Ph.D.

            FileMaker Certified Developer

            Author, FileMaker Pro 10 Bible

            NightWing Enterprises, Melbourne, Australia

            http://www.nightwingenterprises.com

            ------------------------------------------------