You can still do that with repeat forms other than "repeat for each", such as "repeat with...":
Code: Select all
repeat with i = 1 to the number of lines of tData
if item 3 of line i of tData is "bob" then
DoSomethingWith line i of tData
end if
end repeat
For many years that was the only option every xTalk offered, until Rev added the "repeat for each" method, which is so much faster that it's usually well worth the extra couple lines needed to make a new variable:
Code: Select all
put empty into tNuData
repeat for each line tLine in tData
if item 3 of tLine is "bob" then
put tLine &cr after tNuData
end if
end repeat
delete last char of tNuData
While those two repeat forms look superficially similar, they're worlds apart in terms of what's going on in the engine.
With "repeat with" the engine cannot assume the data it's traversing has not changed each iteration through the loop, so when you tell it to get "line i of tData" it has to count line endings from the beginning of tData until it reaches i, and then hand that to you. This means that each time through the loop getting "line i" will be progressively slower.
In contrast, "repeat for each" works with the understanding that the data being traversed will not change, so it counts chunks and parses them out as it goes, keeping track of its place in the data through each iteration so that it doesn't need to start the count over from the beginning each time through the loop.
So while "repeat with" is progressively slower through each iteration, "repeat for each" scales linearly, allowing you to traverse large blocks of data in a small fraction of the time.
The other part of the magic of "repeat for each" is how "put after" has been optimized. In many 4GLs, appending a block of data in memory is a somewhat costly task as the old handle is destroyed and a new, larger one is created. But some years ago Dr. Raney optimized "put after" to involve much fewer operations, merely expanding the block of memory in place, so that it now runs about an order of magnitude faster than in earlier versions of the engine.
So using "repeat for each" with "put after" to build your modified data will usually save you significant time, for the low cost of about two extra lines of code.