paulohr
paulohr

Reputation: 586

Converting C "FOR" loop to Delphi

I'm trying to convert a FOR loop from C to Delphi, but I'm with some doubts:

I know this code in C:

       for (i = 0; i < mb->size; i++)
       {
           //...
       }

is like this in Delphi:

       for i := 0 to mb.size do 
       begin
           //...
       end;

But how is this C code:

       for (i = 0; i < mb->size; i+= mb->data_size)
       {
        //...
       }

might look in Delphi?

       ?

Upvotes: 2

Views: 349

Answers (1)

RRUZ
RRUZ

Reputation: 136391

You cannot use a for in delphi to do this because the variable used to iterate cannot be modified.

So this code

for (i = 0; i < mb->size; i+= mb->data_size)

can be written using a while

  i:=0;
  while (i<mb.size) do
  begin
   // do something
   Inc(i, mb.data_size);
  end;

Upvotes: 10

Related Questions