Recent

Author Topic: Strange: Error: Illegal assignment to for-loop variable "i"  (Read 48788 times)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Strange: Error: Illegal assignment to for-loop variable "i"
« Reply #30 on: August 09, 2012, 08:36:34 pm »
'if i in []' is simply a comparison, not a loop that alters the value of i in any way. You have to add some sort of looping construct (for, while, repeat) to force repeated changes in i's value, e. g.
Code: [Select]
i := 0;
repeat
 if i in [0..4, 11.100] then
  begin
   // whatever
  end;
  inc(i);
until (i > 100);

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: Strange: Error: Illegal assignment to for-loop variable "i"
« Reply #31 on: August 09, 2012, 08:49:23 pm »
Sorry, my bad.  I see it now.  The 1st time I coded the loop and ran it thru the debugger, it appeared that nothing happened.  I added something to do this time and can see that it did in fact loop thru the entire set.

Thanks
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

 

TinyPortal © 2005-2018