2

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?

       ?
1
  • 1
    1) use a "while" loop instead of "for" 2) Your C and Delphi examples are NOT the same. The delphi should read "for i := 0 to mb.size - 1 do" Commented Apr 3, 2012 at 2:37

1 Answer 1

10

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.