Autor
| out of memory problems working in basic
|
MrRudi msx addict Mensajes: 467 | Publicado: Febrero 09 2005, 01:50   |
Quote:
|
and this question for the MSXBASIC geeks......
when i programmed in BASIC, i have the need to exit the bucle FOR/NEXT conditionaly BY example:
FOR I=10 to 1 step -1
if STRIG(pl) then 2000
NEXT I
now the question, this will increase the FOR/NEXT stack?
|
Yes it will...do that a couple of time and your MSX will hang up  unless of course you do "I = 1:return" somewhere in the subroutine starting at 2000
|
|
AuroraMSX
 msx master Mensajes: 1262 | Publicado: Febrero 09 2005, 10:52   |
Quote:
| and this question for the MSXBASIC geeks......
when i programmed in BASIC, i have the need to exit the bucle FOR/NEXT conditionaly BY example:
FOR I=10 to 1 step -1
if STRIG(pl) then 2000
NEXT I
now the question, this will increase the FOR/NEXT stack?
exists a safe way to exit from a bucle like that without increasing the FOR/NEXT stack?
|
Bad solution - before jumping out, set I to the max value and do NEXT:
100 FOR I=1 to 10
110 IF STRIG(0) THEN I=10: NEXT I: GOTO 200
120 NEXT I
130 END
200 ' Do the do
Better solution - avoid FOR/NEXT in this case:
100 I=1
110 IF STRIG(0) GOTO 200
120 I=I+1: IF I<11 GOTO 110
130 END
200 ' Do the dobedeedo
|
|
AuroraMSX
 msx master Mensajes: 1262 | Publicado: Febrero 09 2005, 10:55   |
BTW: It's called a "loop", not a "bucle"  |
|
wolf_
 msx legend Mensajes: 4780 | Publicado: Febrero 09 2005, 11:02   |
bucle could be a perfect typo of cycle when looking at the location of the keys  |
|
Grauw msx professional Mensajes: 1006 | Publicado: Febrero 09 2005, 22:51   |
Quote:
| and this question for the MSXBASIC geeks......
when i programmed in BASIC, i have the need to exit the bucle FOR/NEXT conditionaly BY example:
FOR I=10 to 1 step -1
if STRIG(pl) then 2000
NEXT I
now the question, this will increase the FOR/NEXT stack?
|
The solution is to do a NEXT which ends the loop before the GOTO... Change:
IF STRIG(pl) THEN GOTO 2000
--> into -->
IF STRIG(pl) THEN I=1 : NEXT : GOTO 2000
Of course, you can set I to any value beyond the FOR’s range, e.g. 0, -1 or -999 would do as well in this case.
(sidenote: in the case of IF STRIG(pl) THEN 2000, if you change it into IF STRIG(pl) GOTO 2000 it will do the same, but will be slightly faster!)
~Grauw |
|
Grauw msx professional Mensajes: 1006 | Publicado: Febrero 09 2005, 23:29   |
Ack, Aurora already posted this solution -_-;;...
I wouldn’t call it a ‘bad’ solution though, you’re using a loop for a loop, and that’s perfectly alright. Breaking out of a loop is common practice in many other languages (break in C-style languages), and it is perfectly acceptable...
~Grauw
|
|
AuroraMSX
 msx master Mensajes: 1262 | Publicado: Febrero 10 2005, 10:27   |
Quote:
| Ack, Aurora already posted this solution -_-;;...
|
And D-Tail is getting the credit for it on your BASIC tips page ( map.tni.nl/articles/basic_tips_tricks.php)!
Quote:
| Breaking out of a loop is common practice in many other languages (break in C-style languages), and it is perfectly acceptable...
|
The difference is that C provides a means (break) to break out of the loop. In MSX-BASIC you're using a trick. That's what makes it a less attractive solution, in my view.
[edit]How does that b****y URL BBtag work, dammit?[/edit] |
|
snout
 msx legend Mensajes: 4992 | Publicado: Febrero 10 2005, 10:31   |
[url=http://www.msx.org/]MSX Resource Center[/url]  |
|
AuroraMSX
 msx master Mensajes: 1262 | Publicado: Febrero 10 2005, 11:12   |
Quote:
| [url=http://www.msx.org/]MSX Resource Center[/url]
|
Thanx  Would it be possible to have exactly that text as hint below the message edit box, in the section that explains the BBCode tags? |
|
|
|
|