Author Topic: Please remind what the command to limit loop frequency is  (Read 4109 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Please remind what the command to limit loop frequency is
« on: February 13, 2022, 05:02:50 pm »
For the life of me I simply cannot recall or find what this command is.

There is a command that limits how many iterations of a loop are run every second. For example, if you have a Do ... Loop, you could set it to run this loop no more than 10 times per second to avoid using unnecessary resources.


Marked as best answer by hanness on February 16, 2022, 10:58:45 am

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Please remind what the command to limit loop frequency is
« Reply #1 on: February 13, 2022, 05:06:00 pm »
_LIMIT

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Please remind what the command to limit loop frequency is
« Reply #2 on: February 13, 2022, 05:55:38 pm »
LOL. I actually used the word LIMIT in the title of my question.

I amuse myself sometimes :-)

Thanks!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Please remind what the command to limit loop frequency is
« Reply #3 on: February 13, 2022, 06:09:26 pm »
_LIMIT or DELAY will both work.

The difference is Limit has a maximum, self-adjustable delay, while Delay is a hard-set pause.

Example:

DO
    'Draw graphics that take 1/20th of a second to render
    LIMIT 10
LOOP

Now, with the above, drawing the graphics take 1/20th of a second.  For your Limit to reduce your speed to 10 loops per second, it'd have to calculate and introduce a 1/20th of a second pause.

DO
  'Draw the same graphics
   DELAY 0.1
LOOP

Most folks think the above are interchangeable snippets.  They aren't.  Here, we have a hard-set pause of 1/10th a second in that loop.  With the graphic draw time, it takes.15 seconds for each loop.  We're only running at 6.66 floops per second -- not 10!



Of course, sometimes the Delay is more suitable for your needs than a LIMIT.

For example, say it takes 2/10 of a second to draw the graphics.  A Limit of 10 is going to be completely ignored as the most you can process is 5 loops per second.  If you need the screen to pause no matter what, such as to give time to flash a readable message or press a button, you might want that hard-coded DELAY instead. 

Very similar commands, but slightly different.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Please remind what the command to limit loop frequency is
« Reply #4 on: February 13, 2022, 06:29:24 pm »
damn, Steve, it took you a whole page to explain what bplus said in six characters

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Please remind what the command to limit loop frequency is
« Reply #5 on: February 13, 2022, 06:34:13 pm »
damn, Steve, it took you a whole page to explain what bplus said in six characters

And it took you 16 words to show you never read that page, or else you'd know it was explaining 2 similar commands that could pause a loop.  👍
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Please remind what the command to limit loop frequency is
« Reply #6 on: February 14, 2022, 12:28:21 am »
Don't use _LIMIT or _DELAY for loops.  Use milk.
It works better if you plug it in.

Offline CharlieJV

  • Newbie
  • Posts: 89
    • View Profile
Re: Please remind what the command to limit loop frequency is
« Reply #7 on: February 14, 2022, 08:14:30 am »
Don't use _LIMIT or _DELAY for loops.  Use milk.

+ 1