1
1
Fork 0
mirror of https://github.com/QB64Official/qb64.git synced 2024-07-03 07:41:21 +00:00
qb64/internal/help/_LIMIT.txt

42 lines
1.7 KiB
Plaintext
Raw Normal View History

2016-03-18 11:36:04 +00:00
{{DISPLAYTITLE:_LIMIT}}
2017-10-10 14:55:21 +00:00
The [[_LIMIT]] statement sets the loop repeat rate of a program to so many per second, relinquishing spare CPU cycles to other applications.
{{PageSyntax}}
2021-01-04 18:45:32 +00:00
: [[_LIMIT]] {{Parameter|framesPerSecond!}}
2017-10-10 14:55:21 +00:00
* The {{Parameter|framesPerSecond!}} [[SINGLE]] parameter value adjusts the loops per second of a program loop. '''Do not use negative values.'''
* The loop code is executed before the loop is delayed. Loop cycles below once per second may delay program [[_EXIT]]s.
* _LIMIT measures its interval from the previous time that it was called and minor adjustments are automatically made to ensure that the number of times a loop is repeated is correct overall.
2017-10-10 14:55:21 +00:00
* Loop cycle rates of 1000 or less can '''significantly reduce CPU usage''' in programs.
* Do not use it to limit a loop to '''less than once every 60 seconds'''(.0167) or an [[ERROR Codes|ILLEGAL FUNCTION CALL error]] will occur.
* Do not use _LIMIT as a timing delay outside of loops. Use [[_DELAY]] instead.
2021-02-11 11:41:53 +00:00
* Use _LIMIT to slow down old QBasic program loops that run too fast and use too much CPU.
2017-10-10 14:55:21 +00:00
{{PageExamples}}
''Example:'' Limits loop execution to 30 frames per second and limits the program's CPU usage.
{{CodeStart}} '' ''
2019-04-15 01:15:33 +00:00
{{Cl|PRINT}} "To Quit press ESC key!"
{{Cl|DO}}
{{Cl|_LIMIT}} 30
{{Cl|PRINT}} {{Cl|CHR$}}(26);
{{Cl|IF...THEN|IF}} {{Cl|INKEY$}} = {{Cl|CHR$}}(27) {{Cl|THEN}} {{Cl|EXIT DO}} '' ''
{{Cl|LOOP}}
{{CodeEnd}}
{{OutputStart}}
To Quit press ESC key!
→→→→→→→→→→→→→→→→→→→→
{{OutputEnd}}
:''Note:'' In the above example, _LIMIT has to be within the loop.
{{PageSeeAlso}}
* [[_DELAY]]
* [[TIMER]], [[ON TIMER(n)]]
* [[SLEEP]]
2019-04-15 01:15:33 +00:00
{{PageNavigation}}