Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why does my Loop end after 11 Loops?
#11
Don't forget to close the file! Put "CLOSE" in main program section, before any of the subprograms.
Reply
#12
And don't forget to check for end of file. 4000 is not divisible by 7.
b = b + ...
Reply
#13
I'm in agreement with bplus; it really is a bad idea to read the file like this.
Tread on those who tread on you

Reply
#14
What an excellent group of comments. I particularly like "This is a bad idea". 4000 is not divisible by 7 but 28,000 is. If I have 28,000 data items grabbing them 7 at a time then I was expecting the Recursive Loop to be 4000 loops. After the Input, the program branches off to a Subroutine which deals with these 7 inputted data items. Once done, that Subroutine should bring the focus back to the Recursive Loop where I was expecting it to do it all over again 4000 times. For the most part it was working but I only got 11 loops.

I haven't had a chance to get back to this code to see if STATIC solves it or maybe you guys are onto something there that the looping is being affected by the SEEKing. The Do Loop was safer because it had the control of EOF. I thought my Recursive routine was lacking this and therefore needed some way to start at the beginning of the data file again. I suppose I could Close and Re Open the same file at the start of each Recursion but it seemed a little clumsy.
Reply
#15
Lets clear up one point right now about Seek, it is for a Byte position in the file.

If you are just inputting lines from file with variable lengths Seek is a bad idea.

If each line is exactly the same size in bytes it might be a marvelous alternative to Input! ie you don't need both Input and Seek.
Update: Well maybe Input is redirected by Seek, so I correct myself and apologize I've only used Input to load up arrays to process faster with code in a one time load from start to EOF.

I did miss point that 4000 represented groups of 7 thanks for clarification.
Now if you add or subtract a group of 7 you are stuck with your 4000 hard coded in sub.
Can you make that a more flexible variable?

Thankyou @Balderdash for your support, I was thinking the bad idea comment was bad idea. I do want to encourage experimenting with new concepts, recursion is especially rewarding but tricky, so good for Dimster for trying and asking for help. I think it was the experiments with Seek And recursion both that had me confounded. I like to experiment with one thing at a time specially when playing with recursion.
b = b + ...
Reply
#16
@bplus SEEK is mainly used with INPUT when you have a seperate file which tracks offsets for you, such as if you were trying to index variable length string data for quick access.

I swear, I think I have a few demos floating around here somewhere that showcases that concept.  I'll have to find them later when I have a little extra time to spare.  Wink
Reply
#17
(02-07-2023, 06:53 PM)SMcNeill Wrote: @bplus SEEK is mainly used with INPUT when you have a seperate file which tracks offsets for you, such as if you were trying to index variable length string data for quick access.

I swear, I think I have a few demos floating around here somewhere that showcases that concept.  I'll have to find them later when I have a little extra time to spare.  Wink

Demo here of what I was talking about: https://qb64phoenix.com/forum/showthread.php?tid=1451
Reply
#18
Well I solved the problem as any good programmer would do, I scrapped the road I was going down and combined the Recursion Loop with a Do Loop. Where the Seek was struggling it now flies. So basically the structure of the routine it along these lines

Open the file

Recur 

Sub Recur
 Seek #1,1
  Do While Not EOF(1)
  Input the 7 data items
  DataCount = DataCoount +1
  Call to the Subroutine to deal with the 7 data items
  If DataCount = 4000 then exit sub
  recur
end Sub

This is a simplified layout but you get what I mean by combining the Do Loop and Recursion Loop. I'm absolutely sure there is a more elegant way to have done this but as long as I got my 4000 loops I'm a happy camper. I very much appreciate all the wit and humor that comes with the sage advice. Thanks again.
Reply
#19
(02-07-2023, 06:53 PM)SMcNeill Wrote: @bplus SEEK is mainly used with INPUT when you have a seperate file which tracks offsets for you, such as if you were trying to index variable length string data for quick access.

I swear, I think I have a few demos floating around here somewhere that showcases that concept.  I'll have to find them later when I have a little extra time to spare.  Wink

(02-07-2023, 07:30 PM)SMcNeill Wrote:
(02-07-2023, 06:53 PM)SMcNeill Wrote: @bplus SEEK is mainly used with INPUT when you have a seperate file which tracks offsets for you, such as if you were trying to index variable length string data for quick access.

I swear, I think I have a few demos floating around here somewhere that showcases that concept.  I'll have to find them later when I have a little extra time to spare.  Wink

Demo here of what I was talking about: https://qb64phoenix.com/forum/showthread.php?tid=1451

Yes, I remember you showing us how to do variable length strings. 

It seems like very advanced method for someone who is just trying to get his head around recursion.

But it did give you room to pipe in! ;-))

So Dimster is getting his Seek lessons after all Smile
b = b + ...
Reply
#20
(02-07-2023, 07:42 PM)Dimster Wrote: Well I solved the problem as any good programmer would do, I scrapped the road I was going down and combined the Recursion Loop with a Do Loop. Where the Seek was struggling it now flies. So basically the structure of the routine it along these lines

Open the file

Recur 

Sub Recur
 Seek #1,1
  Do While Not EOF(1)
  Input the 7 data items
  DataCount = DataCoount +1
  Call to the Subroutine to deal with the 7 data items
  If DataCount = 4000 then exit sub
  recur
end Sub

This is a simplified layout but you get what I mean by combining the Do Loop and Recursion Loop. I'm absolutely sure there is a more elegant way to have done this but as long as I got my 4000 loops I'm a happy camper. I very much appreciate all the wit and humor that comes with the sage advice. Thanks again.

@Dimster

You say that works?

How the heck did you get away with having a Do without a Loop?
Show me the code, I am sure there is something missing if it works.
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)