Do something every 1k loops ?

Go to solution Solved by fraizor,

Recommended Posts

Hello

I have a huge loop (around 100k)

I was wondering if there is a way to do a function every 1k loops

i can hardcode the number in IF condition but this looks silly ...

any ideas ?

Share on other sites

Have you looked at using the Mod() function?

Share on other sites

Actually yes , but my brain crashed

Like i can imagine  how mod() could help if the loop is fixed to 100k, so i could easily do mod(\$i, 10000)

However i cant understand how this would work for dynamic loop size ....

One more thing , regarding mod() is  it a heavy function ? wont this waste time and CPU power to calculate mopd in every single loop ?

Share on other sites

• Developers

Not sure why you are at ll worried about cpu cycles when using an interpreter scripting language!

As to the Mod() function, it is simple so I am sure you will be able how to code an if that will be true each 1000 cycles. Just kick your brain in gear at try it as that takes less time than tying your question here.

Live for the present,
Dream of the future,
Learn from the past.

Share on other sites

• Solution

Hmmm..

I should do this:

`if mod(\$i, 10000) = 0 then myfunc()`

am i right ?

Share on other sites

• Developers
10 minutes ago, fraizor said:

am i right ?

Did you try and did it work? 🙄

Spoiler

(it won't do what you initially asked though as 1k <> 10000)

Live for the present,
Dream of the future,
Learn from the past.

Share on other sites

If you are afraid of Mod() you can use a simple counter:

```\$Counter = 0

While True
If \$Counter = 10000 Then
\$Counter = 0
MyFunc()
EndIf
\$Counter += 1
; rest of the code
WEnd```

When the words fail... music speaks.

Share on other sites

5 minutes ago, Jos said:

Did you try and did it work? 🙄

Reveal hidden contents

(it won't do what you initially asked though as 1k <> 10000)

Yes thank you guys , all

Create an account

Register a new account