Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting C "FOR" loop to Delphi

Tags:

c

for-loop

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?

       ?
like image 521
paulohr Avatar asked Dec 21 '25 11:12

paulohr


1 Answers

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;
like image 142
RRUZ Avatar answered Dec 24 '25 02:12

RRUZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!