PDA

View Full Version : Repeat- No Exit? Not Forever? Not Min/Max Times? No Skip/Iterate?



ReneMiner
02-08-2022, 23:14
The Repeat- Until-loops are somewhat like stepchildren:
There is no Exit-Condition,
no Skip Forward(Iterate)
as for the other loops Do/For/While



Repeat When <condition>


were somewhat new - currently While is the only loop that would be skipped if the condition is not met.



Repeat
' statements...

Forever

were a step into direction purebasic - an infinite loop no tests at both ends.
Avoids logical Nonsense as


Do
'...
Loop Until False

which is always confusing and forces the reader to look a second time
What also were nice to have


Repeat

Iterate When [condition] ' skip foward when...

Exit When [condition] ' exit when ...

When [condition] ' continue the loop when...

In all these cases "When" is in a not yet in thinbasic used position :
Iterate is followed by "While,Do,For"
Exit is followed by the same keywords concerning loops ( and Exit Sub/Function)
"Iterate When" and "Exit When" are unique and very much basic-language in the meaning of BASIC
"When" as first keyword on a codeline is not present. Its Twin-brother UNTIL also "eats in foreign families"
-but at home its in first position to close the Repeat-circulation.

WHEN in first position of a line were an alternate "must meet-to continue-condition"
UNTIL is a "continue-as-long-not-meets" condition and also available in Do -Loop/and For-Next

The conditional Exit When or Iterate When were something new - stronger than a one-line-if -clause because it has the ability to change the way though a script where an "If" only filters the flow for the current step the Exit When /Iterate When makes like a jump to the end of the scope of the circular motion
keyword When is already available in


FOR -TO -[STEP]-[WHEN|WHILE|UNTIL]
'...
NEXT


So it were a fitting addition and would make sense to associate WHEN As conditional for Repeat - it came from Nowhere but the one who introduced it certainly knew that it has a special destination and should not play a side-role only but has the strength and power of all other "full-grown" basic-keywords. And living languages change and evolve WHEN these are used.

Back to the Repeat again - somewhat like the For-Next without the requirement of a counter-variable, but unsigned integer ranged
Iteration - which was an idea to For-Next a while ago - the FOR-keyword got stuck somewhere in the unsolved For-Each-mystery...
But Iteration exposes bit similar to Selectexpression the count of already completed repetitions. It will be a huge variable type required,
like 4 Dwords in a GUID-union where bits can be shifted 127 positions - that should serve a few days



Repeat
drawLine(1, Iteration *2) To (99, Iteration *2) In RGB(200- Iteration, Iteration,128)
Until PencilBroke



Where i thought it couldn't be that complicated
For Each <Varname [as Datatype]> Of <Collection|Array> would pretty much set the limit and allow UDTs that are based on the same prototype
being members of a "collection" - which is just a dynamic array of pointers. That the elements in a ollection have something in common is the programmers responsibility - we can not put cats and bananas in the same basket neither. Also that the datatype is a "lower settled type" is forced by logical rules - we can go
For Each Blossom As Flower Of Rosegarden
Blossom.Bloom
Next

requires all elements in rosegarden to derive from prototype "Flower" and type "Flower" must have method "Bloom". If there are tulips or orchids or just a dozen kinds of roses or some weeds or chamomilla the "for-each" puts the name Blossom dimensioned as flower onto all pointers in collection rosegarden - next...

the problem seems to be to coordinate multiple nested loops since when i push my dword along the row of pointers to read where the blossom has to be setat it does not look very complicated. Or could it be that there are no Collections in tb?

Or does For Each work and i use it the wrong way?