Table removeColumn(index) not working correctly?

For completeness’ sake, although I prefer backwards :back: loops for deleting elements, here’s how to do the same w/ a forward :arrow_forward: loop the right way: :smile_cat:

final IntList nums = IntList.fromRange(10);
println(nums);
println("Forwards:");

for(int i = 0; i < nums.size(); ++i) {
  println("index:", i, TAB, "value:", nums.get(i));
  nums.remove(i--);
}

println(nums);
exit();

B/c we’re emptying the whole container, the index i is stuck at value 0 on all iterations. :open_mouth:

Here’s the same example; but this time we’re sparing the indices containing the values 5 & 8: :smirk:

final IntList nums = IntList.fromRange(10);
println(nums);
println("Forwards:");

for (int i = 0; i < nums.size(); ++i) {
  final int val = nums.get(i);
  println("index:", i, TAB, "value:", val);
  if (val != 5 & val != 8)  nums.remove(i--);
}

println(nums);
exit();

The index i ends up w/ value 2; b/c that’s how many indices which has been spared. :nerd_face:

2 Likes