0

So I am just trying to do simple scripting.

Loop
    Exit Loop If [$c = 100]
    Set Variable [$c; Value:1]
    Perform Script ["Import WS Keys 1X"]
    Set Variable [$c; Value:$c + 1]
End Loop

Why doesn't the loop end after 100 times?

1
  • 1
    I don't know what filemaker is but you have Set Variable [$c; Value:1] inside your loop. Wouldn't that reset $c back to 1 each time? Commented Jan 8, 2017 at 10:45

2 Answers 2

1

+1 @michael.hor257k

if you want you loop to have one hundred iterations you should take the set variable statement outside of loop (to be exact the next code will give you 99 iterations):

Set Variable [$c; Value:1]
Loop
   Exit Loop If [$c = 100]
   Perform Script ["Import WS Keys 1X"]
   Set Variable [$c; Value:$c + 1]
End Loop
Sign up to request clarification or add additional context in comments.

2 Comments

There is no need to "initialize" the variable: Set Variable [$c; Value:$c + 1] will set the value of the variable to 1 if it does not exist.
Of course! I just managed to misread your sample code. Indeed, you do not need to initialise the variable and your sample does the 100 loops as well.
1

Try it this way instead:

Loop
  Set Variable [$c; Value:$c + 1]
  Exit Loop If [$c > 100]
  Perform Script ["Import WS Keys 1X"]
End Loop

What you have now alternates the value of $c from 1 to 2 and back:

Loop
    Exit Loop If [$c = 100]
    Set Variable [$c; Value:1]
    # THE VALUE OF $c IS 1
    Perform Script ["Import WS Keys 1X"]
    Set Variable [$c; Value:$c + 1]
    # THE VALUE OF $c IS 2
End Loop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.