It's the same principle with any array. "For" works different in C than pascal. For example:
Code:
// This loop would print all numbers 1 to 10... They become like constants for the loop at beginning
num:=10;
for i:=1 to num do begin
num:=1;
writeln(inttostr(i));
end;
// Same in C would just print 1
num=10;
for (int i=1; i<=num; i++) {
num=1;
printf("%d",i);
}
So you have to restrict what you are deleting from the array or list. Simplest was like mentioned from end to start
Code:
for i:=0 to list.count-1 do
if MarkedForDeletion(list[i]) then list.Delete(i);
But ofc you can do it other ways like:
Code:
i:=0;
while (i<list.count) do begin
if MarkedForDeletion(list[i]) then list.Delete(i)
else inc(i);
end;
Bookmarks