BBC BASIC for Windows
Programming >> BBC BASIC language >> Re: Breaking a loop
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1386770360

Re: Breaking a loop
Post by admin on Nov 24th, 2013, 01:11am

on Nov 23rd, 2013, 11:10pm, TobyWhaymand wrote:
The problem is that I can't seem to find a way to break the loop so that I can continue writing the game without damaging the timer.

I don't know what you mean by "damaging the timer" but to exit the loop you can either use EXIT FOR or you can change the FOR...NEXT loop into a REPEAT...UNTIL loop.

It's not clear to me why you use WAIT 100 in most places but PROCwait_1_second, which has a similar effect, within the loop. Is that connected with your issue?

Quote:
I've been using this command; VDU 23,1,0;0;0;0; to remove the cursor up until that point.

MODE 7 flashing text can affect the cursor (caret) because the screen is constantly being updated, but you should still be able to remove it; it seems to work when I try it here. Incidentally the statement OFF is easier (it does the same thing)!

Quote:
Just to add the print commands are fine. It just the way the out put has formatted in this blog.

You should put listings in code tags to ensure the formatting is preserved.

Richard.
Re: Breaking a loop
Post by TobyWhaymand on Nov 24th, 2013, 12:29pm

Thanks Richard!

I didn't know about the 'insert code' format. I just added this so the code looks different and clearer from the version you read originally

For the intro, the code forms the word 'The' using stars followed by 'NEXT STEP' there a quick message about my book then the game begins after the 'Incoming Transmission' (or rather it will do once I've written the code)

To be honest I didn't think about 'PROCwait_1_second' that certainly is a clearer way of writing code.

I forgot that 'EXIT' is a command in BASIC - I think that should fix the problem.

I'm in LOVE with the 'OFF' command!! - Thanks for letting me know about that!! hehe grin
Re: Breaking a loop
Post by admin on Nov 24th, 2013, 12:51pm

on Nov 24th, 2013, 12:29pm, TobyWhaymand wrote:
To be honest I didn't think about 'PROCwait_1_second' that certainly is a clearer way of writing code.

If you have some reason to want to keep using PROCwait_1_second please make sure you modify it so that it doesn't gobble up 100% CPU time whilst looping. As it stands it's another example of CPU-frying, battery-draining code (albeit that it has a limited duration)!

Most straightforwardly you can add a short WAIT in the loop:

Code:
      DEF PROCwait_1_second
      TIME = 0
      REPEAT
        WAIT 1
      UNTIL TIME >= 100
      ENDPROC 

But simply replacing the whole thing with a WAIT 100 is easier!

Richard.