LB Booster
« goto [loop] »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 05:22am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: goto [loop]  (Read 614 times)
SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: goto [loop]
« Reply #8 on: Nov 1st, 2015, 3:34pm »

Quote:
[loop]
calldll #kernel32, "Sleep", 1 as long, r as long
scan
goto [loop]



Actually LB TIMER is a good delay element, we don't need to use SLEEP.
The only example shipped with LB is "timerexample.bas", in this example TIMER act as a delay element, the next (tick) is done by the loop not by the TIMER.
So I said what am I said, we have not to use (for next loop) but we must use GOTO [LOOP] for contuse running.

Code:

print "let's wait while looping"
    for x = 1 to 10
        print "Now at "; x;". Waiting...";
        call waitMilliseconds 1000
        print "done waiting!"
    next x
    end

sub waitMilliseconds ms
    timer ms, [stopWaiting]
    wait
    [stopWaiting]
    timer 0
end sub

 


The upper is the official example of TIMER, I said to my self if I want my program to work correctly I must limited my TIMER usage with this example. (it is a delay element)

Sarmed
« Last Edit: Nov 1st, 2015, 3:36pm by SarmedNafi » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: goto [loop]
« Reply #9 on: Nov 1st, 2015, 5:15pm »

on Nov 1st, 2015, 3:34pm, SarmedNafi wrote:
Actually LB TIMER is a good delay element, we don't need to use SLEEP.

There are a number of reasons why Sleep is sometimes necessary:
  • For short delays. Although the TIMER parameter is specified in milliseconds, the shortest delay you can actually achieve is about 10 milliseconds and can be as long as 20 milliseconds:

    Code:
        start = time$("ms")
        timer 1, [pause]
        wait
    [pause]
        finish = time$("ms")
        timer 0
        print "Delay was "; finish-start; " milliseconds"
        end 


  • To prevent an 'infinite loop' hogging the CPU. If your program is looping 'doing nothing' it will slow down other processes and can make the PC unresponsive. You should include a Sleep(0) or Sleep(1) in such loops:

    Code:
        calldll #kernel32, "Sleep", 0 as long, r as long 


  • In LB 4 (but not LBB) certain Windows API calls (e.g. the WMLiberty DLL) are incompatible with the WAIT statement, so the replacement code I listed must be used instead (this is not a delay routine):

    Code:
    ' replacement for WAIT
    [loop]
        calldll #kernel32, "Sleep", 1 as long, r as long
        scan
        goto [loop] 


  • In LB 4 (but not LBB) there is a bug which causes TIMER to break the PROMPT statement, so it may be necessary to use Sleep instead. See this page at the LB Bug Tracker wiki.

Richard.
« Last Edit: Nov 2nd, 2015, 01:28am by Richard Russell » User IP Logged

AAW
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx Re: goto [loop]
« Reply #10 on: Nov 1st, 2015, 5:36pm »

Reiterating one of Richard's points:

http://lbpe.wikispaces.com/ScanLoop
User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: goto [loop]
« Reply #11 on: Nov 1st, 2015, 11:57pm »

Thank you Richard for the wider scope explanation. Thank you Alyce for being here.

However any LB user soon or later will find himself wants to use (for example) keyboard pressing response program, he starts thinking of TIMER then he shocked with the unreliable performance of Liberty Basic, unless Carl will fix it, or he will jump to the Booster LBB (that what I did).

Regards,
« Last Edit: Nov 2nd, 2015, 12:08am by SarmedNafi » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »


This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls