# Using a forEach: Would this satisify the looping through the list requirement

**URL:** <https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664>\
**Category:** AP Prep\
**Created:** [February 22, 2023, 7:15pm UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664 "2023-02-22T19:15:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff.rhodes](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jeff.rhodes/32/7758_2.png) [@jeff.rhodes](https://forum.code.org/u/jeff.rhodes)\
**Post date:** [February 22, 2023, 7:15pm UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/1 "2023-02-22T19:15:50Z")

</div>

I have a student who used forEach. to look through a list they created. They asked if this is acceptable and I honestly do not know, better to ask than assume. Any feedback would be appreciated.

This is function he is calling:

> **[Array.prototype.forEach() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)**
>
> The forEach() method executes a provided function once
> for each array element.

---

<div class="post-metadata">

**Author:** ![madeline\_r\_burton](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/madeline_r_burton/32/5037_2.png) [@madeline\_r\_burton](https://forum.code.org/u/madeline_r_burton)\
**Post date:** [February 23, 2023, 4:21am UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/2 "2023-02-23T04:21:34Z")

</div>

Hi Jeff,

I think I need a little clarity on what it is you’re looking for here. If this is a project that a student is currently working on for the AP, then we cannot give any guidance about how they should implement any portion of the create task. In that case, the best I would do is remind them that they are going to write about this code. Have them perform a gut check - do they feel confident explaining this in the written portion? If so, carry. on. If no, consider other options.

If that’s maybe not your question, let me know and I’ll try to add a better response!

---

<div class="post-metadata">

**Author:** ![jeff.rhodes](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jeff.rhodes/32/7758_2.png) [@jeff.rhodes](https://forum.code.org/u/jeff.rhodes)\
**Post date:** [February 23, 2023, 12:16pm UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/3 "2023-02-23T12:16:23Z")

</div>

There is 0 code written yet, they were asking for clarification on the rubric and rules. As I don’t know if a forEach call would work under how it is written in the rubric or if it would count.

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [February 24, 2023, 5:55am UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/4 "2023-02-24T05:55:29Z")

</div>

Theoretically it should count, forEach is a prototype method used in arrays to iterate through elements in the list / array for example

```auto
var array = [1, 2, 3, 4, 5, 6];
// forEach outputs the same as a basic iterator
array.forEach(function(element) {
console.log(element);
});
// I'd assume something would count toward the rubrick
for(var i = 0; i < array.length; i++) {
var element = array[i];
console.log(element);
}

```

In my opinion the only way i could see this being disqualified is if you needed the current index within the iterator since this is a comparison throughout the list, other than that I’d consider it a loop just like **while(){ } do { } while() or for** loops I’d also imagine in this situation that forEach also looks much more readable than the basic iterator indicating that something is being searched for, not changed

hope this helps  
Best, Varrience

---

<div class="post-metadata">

**Author:** ![jeff.rhodes](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jeff.rhodes/32/7758_2.png) [@jeff.rhodes](https://forum.code.org/u/jeff.rhodes)\
**Post date:** [February 24, 2023, 12:34pm UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/5 "2023-02-24T12:34:26Z")

</div>

Thank you, that was my line of thought.

---

<div class="post-metadata">

**Author:** ![mkmietowicz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mkmietowicz/32/6322_2.png) [@mkmietowicz](https://forum.code.org/u/mkmietowicz)\
**Post date:** [February 25, 2023, 3:03am UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/6 "2023-02-25T03:03:40Z")

</div>

Hi @jeff.rhodes,

If this is for the Create PT, I would caution you that you are not allowed to tell the student whether you feel the forEach would count. You can certainly ask them if _they_ think it should count, but providing guidance of any kind is strictly not allowed.

–Michael K.

---

<div class="post-metadata">

**Author:** ![najemz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/najemz/32/8047_2.png) [@najemz](https://forum.code.org/u/najemz)\
**Post date:** [March 15, 2023, 4:11am UTC](https://forum.code.org/t/using-a-foreach-would-this-satisify-the-looping-through-the-list-requirement/37664/7 "2023-03-15T04:11:05Z")

</div>

Under section “Completing the Performance Task” on page 201 of the “AP Computer Science Principles - COURSE AND EXAM DESCRIPTION”, it says (addressing the student,)

“[you may] **Seek clarification from your teacher or AP Coordinator** on the **prompts** and **submission requirements** for the performance task when you do not understand the directions.”

To me, the question of the student about the .forEach in this post is a clarification question, and thus it is permissible to answer.
