# Table removeColumn(index) not working correctly?

**URL:** <https://discourse.processing.org/t/table-removecolumn-index-not-working-correctly/17585>\
**Category:** Coding Questions\
**Created:** [February 6, 2020, 12:59pm UTC](https://discourse.processing.org/t/table-removecolumn-index-not-working-correctly/17585 "2020-02-06T12:59:31Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 12, 2020, 6:47pm UTC](https://discourse.processing.org/t/table-removecolumn-index-not-working-correctly/17585/4 "2020-02-12T18:47:49Z")

</div>

> [@jeremydouglass](#):
>
> Also, _in general_, do not iterate over things forward and delete (due to the skipping problem, above).

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

```auto
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. 😮

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

```auto
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. 🤓

---

_[View the full topic](https://discourse.processing.org/t/table-removecolumn-index-not-working-correctly/17585)._
