Iterating the iterator

BASIC Beginner

3 replies to this topic

#1 KayBeeOFFLINE

KayBee

• 19 posts
• Calculating...
• Location:Porter Ranch, CA

Posted Mon Feb 18, 2019 11:27 PM

Hi Atarians,

I'm working through learning BASIC and have stumbled. How can you iterate something that is already iterating.

Say I have this:

10 X=1

15 FOR T = 1 TO 5

20 PRINT X

25 X=X+1

30 NEXT T

RUN

1

2

3

4

5

and I want to iterate it so I get this the next time:

6

7

8

9

10

but not with a GOTO. Nested maybe? Or something more elegant? Any advice would be appreciated.

Thank you.

KB

#2 777ismynameOFFLINE

777ismyname

Star Raider

• 92 posts
• Location:Blue Ridge Mountains, North Carolina

Posted Tue Feb 19, 2019 2:39 AM

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

I'm not sure this is what you're looking for. You could certainly nest, but this would be faster.

#3 ggnOFFLINE

ggn

Stargunner

• 1,463 posts
• Location:Athens, Greece

Posted Tue Feb 19, 2019 3:11 AM

10 X=1:GOSUB 100
20 X=6:GOSUB 100
30 END
100 FOR T = 1 TO 5
110 PRINT X
120 X=X+1
130 NEXT T
140 RETURN

#4 _The Doctor__ONLINE

_The Doctor__

Flux Capacitor Master Craftsman

• 6,547 posts
• Location:10-0-11-00:02

Posted Tue Feb 19, 2019 8:59 AM

how about 5 iterations of 5, this is something quick, there are prolly better solutions

10 X=1:M=5

15 FOR I=1 TO 5:FOR T=X TO M

20 ? X

25 X=X+1

30 NEXT T:M=M+5:NEXT I

if you don't set M=5, it will give you 1 thru 20

If you don't set X=1 it will give you 0 thru 20

want 0 thru 19?

you can alter slightly for each following simple changes like the ideas above and....

15 FOR I=1 TO 5:FOR T=X TO M-1

20 ? X

25 X=X+1

30 NEXT T:M=M+5:NEXT I

want to 24? put line in

10 M=5

HEY Let's try to do 1-55

10 X=1:M=10

15 FOR I=1 TO M:FOR T=X TO M

20 ? X

25 X=X+1

30 NEXT T:M=M+5:NEXT I

or just ask what you want X, M etc to be and have the user supply what they want.... looking at what I posted it should be easy for you to make it so the starting point, ending point, can be whatever they wish, and you could add another piece to the puzzle and do other iterations within at any arbitrary #

just because we can... 1 to 30

10 X=1:M=10

15 FOR I=1 TO 5:FOR T=X TO M

20 ? X

25 X=X+1

30 NEXT T:M=M+5:NEXT I

let's not forget you can adjust the range a little as well,

10 X=1:M=9

15 FOR I=1 TO M:FOR T=X TO M

20 ? X

25 X=X+1

30 NEXT T:M=M+5:NEXT I

you see M=9 gets you 1 thru 49

you go to 29 by choosing what the FOR I=1 TO ? is by making the ? (5 or M)  to 5 again, etc....  spend the day toying around with it and it makes sense why this works as it does...

Edited by _The Doctor__, Tue Feb 19, 2019 9:57 AM.

Also tagged with one or more of these keywords: BASIC, Beginner

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users