Eloquent way to iterate in Basic?

Blitz3D Forums/Blitz3D Programming/Eloquent way to iterate in Basic?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Let's say I want to implement a Prime Number Generator which returns a list of numbers, one at a time. I want to be able to run two or more generators simultaneously, so I can't use globals. I would imagine I'd need to implement three functions:

PNG_start.PNG(begin%, end%)
PNG_next(g.PNG)
PNG_get(g.PNG)

And use them like so:

g.PNG = PNG_start(1, 100)
While PNG_next(g)
	n = PNG_get(g)
	Print n
Wend


Three lines to start a loop seems excessive to me. Can anyone think of a more concise/eloquent way to write this? Or a better API?


Putting these statements on one line looks awful to me, mostly because the line doesn't start with a loop keyword so it's not immediately evident that a loop is beginning.

g.PNG = PNG_start(1, 100) : While PNG_next(g) : n = PNG_get(g)
	Print n
Wend


In C, you can use for(;;), which - although a little wordy - still looks good to me:

for( PNG g = PNG_start(1, 100); PNG_next(g); int n = PNG_get(g) ) {
	printf(n);
}



Any thoughts?