How to iterate the iteration

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
KayBee
Posts: 12
Joined: Mon Feb 13, 2017 5:34 pm

How to iterate the iteration

Post by KayBee »

Cool ZXers,

Say I have this:

10 LET X=1
15 FOR T = 1 TO 5
20 PRINT X
25 LET X=X+1
30 NEXT T

RUN

1
2
3
4
5

But what if I want the whole thing (lines 10-30) in another loop (if that's the most elegant approach), so it does:

6
7
8
9
10

The next time I run it. And so on, each time I run it, the sequence is iterated.

Learning BASIC is fun, but I'm stubbing my toe here and I would appreciate your advice.

Thank you.

KB
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: How to iterate the iteration

Post by 1024MAK »

If you keep your program as it is, instead of using RUN to run it a second (or third) time, you instead use GO TO 15, it will do what you want. You will need to add a CLS or a SCROLL to prevent running into the bottom of the screen if you use GO TO 15 too many times though.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
KayBee
Posts: 12
Joined: Mon Feb 13, 2017 5:34 pm

Re: How to iterate the iteration

Post by KayBee »

Hi Mark,

Thank you for taking time to reply, but I am aware of that method. I am interested in solving this concept.

Cheers,

KB
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: How to iterate the iteration

Post by XavSnap »

10 LET X=1
15 FOR X = X TO X+5
20 PRINT X
30 NEXT X
40 GOTO 35

:oops:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
KayBee
Posts: 12
Joined: Mon Feb 13, 2017 5:34 pm

Re: How to iterate the iteration

Post by KayBee »

You folks that know BASIC well may indeed be slapping your foreheads at my question...I keep thinking there is a nested solution, or something else.

Thanks again for taking a look.

KB
User avatar
1024MAK
Posts: 5101
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: How to iterate the iteration

Post by 1024MAK »

As BASIC variables are CLEARed when RUN is used, if you wish to retain a value in between RUNs, you can store it in an area of RAM that BASIC will leave alone.

So for example, on a ZX81, in a REM statement in the first line of a program.
Listing
Listing
Note that I entered POKE 16514,0 as a direct statement before running it, but if you use the appropriate character in the REM line, you don’t have to. If you wish to edit the REM line, it’s best to enter it afresh rather than edit it in case the number/character upsets the editor.
First RUN
First RUN
Second RUN
Second RUN
Third RUN
Third RUN
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: How to iterate the iteration

Post by XavSnap »

:shock:

The main question is : "How to save the "Vars" memory room in Basic ?" to retrieve an ancien memory variables snap...
;)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: How to iterate the iteration

Post by XavSnap »

or...

10 LET Z=16417
15 FOR X = PEEK(Z) TO PEEK(Z)+5
20 PRINT X
30 NEXT X
35 POKE Z,X
37 CLS
40 GOTO 35
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply