# For Loop Problem

**URL:** <https://discourse.processing.org/t/for-loop-problem/4913>\
**Category:** Coding Questions\
**Created:** [October 27, 2018, 12:40am UTC](https://discourse.processing.org/t/for-loop-problem/4913 "2018-10-27T00:40:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [October 27, 2018, 12:40am UTC](https://discourse.processing.org/t/for-loop-problem/4913/1 "2018-10-27T00:40:31Z")

</div>

I have code that initializes a 2d array, but when the Y goes to zero it gives an array out of bounds exception. Why is this? How do I fix it?

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [October 27, 2018, 1:37am UTC](https://discourse.processing.org/t/for-loop-problem/4913/2 "2018-10-27T01:37:11Z")

</div>

It’s impossible to know without seeing the code in question. Post the line that declares the array. Post the loops that you use to loop over the array elements. Tell us which line is highlighted when you get the error.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [October 27, 2018, 11:35am UTC](https://discourse.processing.org/t/for-loop-problem/4913/3 "2018-10-27T11:35:27Z")

</div>

As TfGuy44 said, you should Post some code, But as far as i understood your Problem, your Second Array probably isn‘t initialized correctly.

---

<div class="post-metadata">

**Author:** ![Grimtin10](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@Grimtin10](https://discourse.processing.org/u/Grimtin10)\
**Post date:** [October 27, 2018, 11:59pm UTC](https://discourse.processing.org/t/for-loop-problem/4913/4 "2018-10-27T23:59:14Z")

</div>

im going to respond later.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 31, 2018, 5:16pm UTC](https://discourse.processing.org/t/for-loop-problem/4913/5 "2018-10-31T17:16:07Z")

</div>

Hope you resolved your problem. Don’t forget that the forum is here to help if you can share your code and point out the specific problem you are having.
