Search code examples
delphidelphi-7

Using Continue in a While loop


Can the Continue be used in a While loop when working with text files?

I would like to do some processing and check some values. If true, i would like to skip a iteration. If false, i would like to continue with the next set of lines (continue processing).

while not EOF(InFile) do  
begin  
 DoSomething;  
 if (AcctTag = '') OR (MasterId = '') then  
  Continue;  
 DoSomething;  
end;  

Does the continue in this case skip a iteration?


Solution

  • A test isn't even necessary. The documentation already tells you the answer:

    In Delphi code, the Continue procedure causes the flow of control to proceed to the next iteration of the enclosing for, while, or repeat statement.

    Notice that there are no caveats about what the loop is doing. The Continue statement proceeds to the next iteration of any loop. In your case, that means Eof will be checked again, and then the body of the loop will run.