LB Booster
Programming >> Liberty BASIC language >> goto [loop]
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1446321856

goto [loop]
Post by joker 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?
Re: goto [loop]
Post by Richard Russell 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.

Re: goto [loop]
Post by SarmedNafi 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
Re: goto [loop]
Post by SarmedNafi 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
Re: goto [loop]
Post by Rod 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.
Re: goto [loop]
Post by Richard Russell 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.

Re: goto [loop]
Post by Rod 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.
Re: goto [loop]
Post by joker 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
Re: goto [loop]
Post by SarmedNafi 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
Re: goto [loop]
Post by Richard Russell 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:

Richard.

Re: goto [loop]
Post by AAW on Nov 1st, 2015, 5:36pm

Reiterating one of Richard's points:

http://lbpe.wikispaces.com/ScanLoop
Re: goto [loop]
Post by SarmedNafi 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,