Iterating the iterator

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
KayBee
Berk
Posts: 17
Joined: Thu May 31, 2018 2:14 pm

Iterating the iterator

Post by KayBee » Tue Feb 19, 2019 1:27 am

Hi BASIC Brains,

I am trying to get my head around iterating something that is already iterating. Hmm, I hope that made sense. Well, let's 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 to iterate, so it does:

6
7
8
9
10

The next time I run it. Yes I could add a GOTO at the end, but that's not what I'm after.

Thank you fine folks, I appreciate your time.

KB
0 x

User avatar
djnzx48
Manic Miner
Posts: 568
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Iterating the iterator

Post by djnzx48 » Tue Feb 19, 2019 6:10 am

Maybe not quite what you wanted, but you can do this at least:

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

As FOR-NEXT loop variables can be used just like normal variables, here X is being used to initialise itself in the loop. Also you can use GOTO instead of RUN to run a program, which stops the variables from being cleared.
0 x

AndyC
Manic Miner
Posts: 251
Joined: Mon Nov 13, 2017 5:12 am

Re: Iterating the iterator

Post by AndyC » Tue Feb 19, 2019 7:09 pm

RUN clears all the variables, so if you want to do this you either have to avoid using it to restart the program or CLEAR memory to give you some free bytes and then POKE/PEEK numbers from there, beyond the reach of what BASIC will interfere with.
0 x

User avatar
1024MAK
Manic Miner
Posts: 533
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Iterating the iterator

Post by 1024MAK » Fri Feb 22, 2019 5:14 pm

Hmm... (click)...

Mark
0 x

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1224
Joined: Mon Nov 13, 2017 3:16 pm

Re: Iterating the iterator

Post by Ast A. Moore » Fri Feb 22, 2019 5:40 pm

1024MAK wrote:
Fri Feb 22, 2019 5:14 pm
Hmm... (click)...
Déjà vu.
0 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

KayBee
Berk
Posts: 17
Joined: Thu May 31, 2018 2:14 pm

Re: Iterating the iterator

Post by KayBee » Sat Feb 23, 2019 3:48 pm

Yes,

I asked it for the Atari too:

http://atariage.com/forums/topic/288390 ... -iterator/

Each community has its bright lights, each with their own style of answering. Answers can be like books, some connect with you and some don't. I am determined to finish this game idea. At first I wanted to make a sell-worthy game for the TS1000, but then I fell in love with the Spectrum, and I want the game to have some square wave sound effects.

Thank you.

KB
0 x

Post Reply