# Help with for()

**URL:** <https://discourse.processing.org/t/help-with-for/1194>\
**Category:** Coding Questions\
**Created:** [June 24, 2018, 1:05am UTC](https://discourse.processing.org/t/help-with-for/1194 "2018-06-24T01:05:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jferreira](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jferreira/32/565_2.png) [@jferreira](https://discourse.processing.org/u/jferreira)\
**Post date:** [June 24, 2018, 1:05am UTC](https://discourse.processing.org/t/help-with-for/1194/1 "2018-06-24T01:05:00Z")

</div>

Hello!  
I am working in a minigame based in StarCastle(Vectrex), and i am trying to draw the shields:

```auto
void drawLines(){ 
    for(ArrayList<PVector> line : this.shield){
      switch(this.shield.indexOf(line)){
        case 0: stroke(255,0,0); break;
        case 1: stroke(255,255,0); break;
        case 2: stroke(0,255,0); break;
      }
      for(PVector miniShield : line){
        int iMiniShield = line.indexOf(miniShield);
        if(iMiniShield>0){
          PVector LastMiniShield = line.get(iMiniShield-1);
          strokeWeight(3-line.get(iMiniShield).z);
          if(line.get(iMiniShield).z>0)
            line(miniEscudo.x, miniEscudo.y, miniEscudoAnterior.x, miniEscudoAnterior.y);
        }
      }
    }
  }

```

this.Shield is an ArrayList that has 3 ArrayLists with 8 PVectors.

My problem is that I always get 0 when I use.indexOf(), what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 24, 2018, 2:58am UTC](https://discourse.processing.org/t/help-with-for/1194/2 "2018-06-24T02:58:09Z")

</div>

First, you need to provide more code. For instance, where is the the definition of your **line** object? Also, consider changing this name as line is a reserved word for the `line()` function.

Also, format your code properly before you posted here. In the PDE, press `ctrl+t`. Here, for a doe block, enclose your code in a pair of triple back ticks.

Kf

---

<div class="post-metadata">

**Author:** ![jferreira](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jferreira/32/565_2.png) [@jferreira](https://discourse.processing.org/u/jferreira)\
**Post date:** [June 24, 2018, 4:57am UTC](https://discourse.processing.org/t/help-with-for/1194/3 "2018-06-24T04:57:14Z")

</div>

Well, I solved the problem using for(init; test; update) instead for(datatype element : array), the problem was that **array.indexOf(element)** inside for(datatype element : array) was always getting 0.
