Iterating the iterator

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

Iterating the iterator

Post by KayBee »

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
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Iterating the iterator

Post by djnzx48 »

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.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Iterating the iterator

Post by AndyC »

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.
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Iterating the iterator

Post by 1024MAK »

Hmm... (click)...

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Iterating the iterator

Post by Ast A. Moore »

1024MAK wrote: Fri Feb 22, 2019 5:14 pm Hmm... (click)...
Déjà vu.
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
Drutt
Posts: 17
Joined: Thu May 31, 2018 3:14 pm

Re: Iterating the iterator

Post by KayBee »

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
Post Reply