Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Oh I see... Thanks Griff...Scan for will process a whole table start to finish excluding the records that do not match the for clause, like a filter.
Scan while starts from where the the current record pointer is, and stops when the while clause is no longer valid.
So for scan while, you position (typically) using a seek to get the first match, then process the next x records that work
with the clause and then stop.
Create Cursor test (id int)
For i = 1 to 10
Append Blank
EndFor
Go 2
Scan While Recno()<5
? Recno()
EndScan
? Recno(), Eof()
Create Cursor test (id int, field2 int)
For i = 1 to 10
insert into test values (i,1)
EndFor
Replace field2 with 2 For inlist(Recno(),1,2,3,5)
Go top
? 'while'
Scan While field2=2
? Recno()
EndScan
? 'for'
Scan for field2=2
? Recno()
EndScan
scan for will use indexes and is Rushmore optimisable, scan while is a straightforward iteration while the condition is true.Hi everyone...i have been using these two... scan for and scan while... and it works perfectly may you help me explain further how these two works so that i could use the most appropriate scan basing on my needs... Thanks in advance....
I was gonna answer but all these other guys kind of beat the answer to death already. I absolutely couldn't think of a thing to add!Hi everyone...i have been using these two... scan for and scan while... and it works perfectly may you help me explain further how these two works so that i could use the most appropriate scan basing on my needs... Thanks in advance....
There are many great answers so I hope I don't contradict any but one thing I'd make clear is the FOR and WHILE clauses are not mutually exclusive, I frequently use both together. There are scenarios where using both together can be beneficial. Especially if you want to reduce the amount of indented blocks, perhaps making some code clearer, removing some lines of code because VFP will do other things automatically and SCAN provides some god flexibility.Hi everyone...i have been using these two... scan for and scan while... and it works perfectly may you help me explain further how these two works so that i could use the most appropriate scan basing on my needs... Thanks in advance....
SELECT bob
SET ORDER TO id
SEEK tnId
IF FOUND()
DO WHILE id = tnId AND NOT EOF("bob")
IF {some condition}
{do some stuff}
ENDIF
SELECT bob
SKIP
ENDDO
ENDIF
SELECT bob
SET ORDER TO id
IF SEEK(tnId)
SCAN REST ;
FOR {some condition} ;
WHILE id = tnId
{do some stuff}
ENDSCAN
ENDIF
SEEK specificorderid && position on first orderitem of a specific order by the orderid (the data structure of an orderitem needs to have an orderid and unprocessed status besides other fields like product, no of items, etc):
SCAN REST FOR unprocessed WHILE orderid=specificorderid
...
ENDSCAN
SEEK specificorderid && position on first orderitem of a specific order by the orderid
SCAN REST WHILE unprocessed
...
ENDSCAN
SCAN For orderid=specificorderid and unprocessed
...
ENDSCAN
thanks griff... its only now that i know that scan for will process all records all the while i thought both process all records in a table... i usually use scan to look and processes for 2 or more records in the whole table... i also use count... thanks Chriss and everyone...Oh I see... Thanks Griff...