Our Preferred 5 Star Hosting Provider - Award Winning FileMaker Pro Hosting
Results 1 to 2 of 2
  1. #1
    Senior Moderator - FMT Preferred Trainer - Consultant: Australia, New Zealand, Japan & Pacific Rim David Head's Avatar
    Join Date
    Apr 2001
    Sydney, NSW Australia
    FileMaker Pro Software
    FileMaker Pro 15 Advanced
    Windows & Mac
    Skill Level
    Last Post
    Local Date
    Local Time
    03:17 PM
    Last Active

    Lightbulb Tip: Exiting a loop by incrementing and testing a variable

    Loops are used in FileMaker scripting for a range of operations. In many cases, you want the loop to run through a specified number of times and then exit. This can be done with a variable used as a counter. At the end of the loop, the counter is compared to something (a field value, the record count, etc) and will exit if the condition is true.

    A typical loop structure looks like this:

    Set Variable [$counter; 0]
    # Do stuff here
    Set Variable [$counter; $counter + 1]
    Exit Loop If [$counter ≥ 10]
    End Loop

    But you can do the incrementing and testing of the variable in one step:

    Set Variable [$counter; 0]
    # Do stuff here
    Exit Loop If [Let ($counter = $counter + 1; $counter ≥ 10)]
    End Loop

    The Let statement says, increment the variable and then return the result of the Boolean expression ($counter ≥ 10). If the expression returns 1 (true) then exit the loop; if not, go around again.

    So what's the point? Is it any faster? Probably not. But it does consolidate the operation of exiting the loop into a single coherent script step.

    Another interesting point is that the step before the loop to set the variable is not actually required in FileMaker Pro. If the $counter does not exist on the first loop, FileMaker Pro will create it.

    Now wouldn't it be cool if we could increment variables like some programming languages:

    David Head
    FileMaker 15 Certified Developer
    FBA Trainer
    LinkedIn Profile

    There is always a well-known solution to every human problem - neat, plausible, and wrong.
    H. L. Mencken, Prejudices: Second Series, 1920

  2. #2
    FMT Preferred FileMaker Consultant - Trainer jaymo67's Avatar
    Join Date
    Sep 2014
    Chino Hills, CA
    FileMaker Pro Software
    FileMaker 15 Advanced
    Skill Level
    Last Post
    Local Date
    Local Time
    10:17 PM
    Last Active
    Nice tip David!
    FileMaker Developer for over two decades. Certified in FileMaker 7, 8, 9, 10, 11, 12, 13, 14 and 15.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Exiting a Loop
    By jaymo67 in forum NEW! JMO's Philosophy of FileMaker
    Replies: 8
    Last Post: 03-02-2017, 03:05 PM
  2. exit inner loop not working and exits main loop
    By alienandra in forum FileMaker 13 - All Versions
    Replies: 7
    Last Post: 11-03-2015, 07:24 PM
  3. (text parsing) loop through extracted variable list items
    By edented in forum ScriptMaker and Scripting
    Replies: 2
    Last Post: 07-25-2012, 02:05 PM
  4. Replies: 2
    Last Post: 05-04-2011, 10:03 PM
  5. End loop based on numeric variable
    By stuff03 in forum ScriptMaker and Scripting
    Replies: 1
    Last Post: 02-11-2009, 04:38 PM

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Welcome to the Original FileMaker Forum
With designated forums for almost every FileMaker topic...FileMaker Today is a FREE to join community where you can boost your FileMaker expertise, build better apps & solutions and interact with over 42,000+ FileMaker Developers from all over the world. If you're building FileMaker solutions, this is the place for you.
Follow FMT
We Are FMT
FMT is home of The World's leading FileMaker News Site, Worldwide Developer Directory, FileMaker Connect Community and so much more.