This site requires JavaScript, please enable it in your browser!
Greenfoot back
thekidj
thekidj wrote ...

2013/10/31

Why does my for loop add the course to every element?

thekidj thekidj

2013/10/31

#
I want to add the course to one index, but it adds it to all of the indexes.
    public void addCourse(Course newCourse)
    {
        for (int index = 0; index < courses.length; index++)
        {
            courses[index] = newCourse;
        }
    }
erdelf erdelf

2013/10/31

#
why are u using a for-loop when u just want one index to be set`?
You need to login to post a reply.