LB Booster
« goto [loop] »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:17am



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 607 times)
joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx goto [loop]
« Thread started on: Oct 31st, 2015, 8:04pm »

I've seen this several times and am somewhat confused (not so hard to believe!)

Code:
[loop]
     wait

[someOtherCode]
    ' blah
    ' blah
    ' blah

    goto [loop]
 


The other way I've seen this is to replace the "goto [loop]" with "wait". There could be many labeled procedures with this at the end.

Is there a significant difference in the two methods? Is "wait" the same "wait" no matter where it is in the code?
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: goto [loop]
« Reply #1 on: Oct 31st, 2015, 8:11pm »

on Oct 31st, 2015, 8:04pm, pnlawrence wrote:
I've seen this several times and am somewhat confused (not so hard to believe!)

Me too. It stems from a misunderstanding, I expect. It makes much more sense (to me) to replace the goto [loop] with another wait.

There is a bug in LB 4 which (in obscure circumstances) can cause execution to continue 'through' the wait (in which case the two options would behave differently), but it shouldn't happen, and never does in LBB.

Richard.
« Last Edit: Oct 31st, 2015, 11:27pm by Richard Russell » User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: goto [loop]
« Reply #2 on: Nov 1st, 2015, 01:56am »

Well,
I think Richard points to another problem.

The example code could be useful if my routines make "SET", the "RESET" routine should be between [loop] and wait. We will use one "reset" routine for all other "set" routines.

Richards answer related to the problem of TIMER in Liberty Basic.

Sarmed
« Last Edit: Nov 1st, 2015, 01:16am by SarmedNafi » User IP Logged

SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx Re: goto [loop]
« Reply #3 on: Nov 1st, 2015, 01:09am »


In Liberty Basic because timer is broken, we have to use the posted example to get raid of the absence of a good TIMER.
Or the only other choice is to use LBB with correct TIMER.
If Carl fix the TIMER, Liberty Basic will work in 95% of it's abilities, the remaining 5% less is for the other bugs not fixed.

Sarmed
« Last Edit: Nov 1st, 2015, 01:21am by SarmedNafi » User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: goto [loop]
« Reply #4 on: Nov 1st, 2015, 07:20am »

To answer the initial question. A program is either a static sequence of code blocks [labels] or Subs that will be called by events like a button press or mouse click or the timer firing. In which case the code jumps to the code block and executes to the wait statement. It then sits idle till the next event. Or the program loops and runs specific sequences of code blocks in a loop. This is when go to [loop] is most often seen. The loop can also be repeated by using a timer statement.

So the difference is all about exactly what program flow you need, looping or static or indeed combinations where you have a core loop and static code blocks that are called occasionally.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: goto [loop]
« Reply #5 on: Nov 1st, 2015, 07:25am »

on Nov 1st, 2015, 01:09am, SarmedNafi wrote:
In Liberty Basic because timer is broken, we have to use the posted example to get raid of the absence of a good TIMER.

No, it makes no difference. In the code posted by the OP, goto [loop] has the same effect as wait; irrespective of whether you are using TIMER (in LB or LBB).

Quote:
Richards answer related to the problem of TIMER in Liberty Basic.

No it didn't! The bug related to TIMER in JB/LB is that you cannot use a SUB handler, but that's a completely separate issue from the one raised by the OP, and is unaffected by it.

At the risk of adding more confusion, there is another bug in LB which means you occasionally need to use this code instead of wait, but again it's a separate issue:

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

Richard.
« Last Edit: Nov 1st, 2015, 07:32am by Richard Russell » User IP Logged

Rod
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 110
xx Re: goto [loop]
« Reply #6 on: Nov 1st, 2015, 08:20am »

Also in the dim and distant past Liberty needed that form of go to loop , wait. So if you are looking at very old or original code examples you will see that format. But the wait statement has been improved. So you can wait anywhere in a program and be whisked off to the next event.
User IP Logged

joker
Global Moderator
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 157
xx Re: goto [loop]
« Reply #7 on: Nov 1st, 2015, 08:54am »

Quote:
Is there a significant difference in the two methods? Is "wait" the same "wait" no matter where it is in the code?


Ok, most everyone will / does understand how a GOTO works, so that isn't part of my confusion. Perhaps Rod hit on the reason that I've been seeing it done, as I've been doing a lot of reading (mostly in archives, but what else is there?) trying to wrap my brain around GUI programming.

I appreciate the comments. Good to know those workarounds for known bugs in LB, too.

I'm getting from all this that wherever you put the wait command, the program is essentially going back into the same loop "under the hood", but by adding a goto one will actually be adding code to get to that "under the hood" loop.

That's an easy decision for me to make. smiley
User IP Logged

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