Skip to content

Suggested Edits: Lesson 3 - Chapter 12 For Loops #687

@chewhx

Description

@chewhx

Summary

  1. Rename counter to resultIndex.
  2. Rename i to zombieIndex.

This will make understanding easier for everyone, especially beginners to programming and the concepts.
This is from my experience, going through the cryptozombies curriculum the second time to revise all the concepts.

Original:

...

  1. Declare a uint called counter and set it equal to 0. We'll use this variable to keep track of the index in our result array.
  2. Declare a for loop that starts from uint i = 0 and goes up through i < zombies.length. This will iterate over every zombie in our array.
  3. Inside the for loop, make an if statement that checks if zombieToOwner[i] is equal to _owner. This will compare the two addresses to see if we have a match.
  4. Inside the if statement:
    1. Add the zombie's ID to our result array by setting result[counter] equal to i.
    2. Increment counter by 1 (see the for loop example above).

Suggested

...

  1. Declare a uint called resultIndex and set it equal to 0. We'll use this variable to keep track of the index in our result array.
  2. Declare a for loop that starts from uint zombieIndex = 0 and goes up through zombieIndex < zombies.length. We will use this variable to iterate over every zombie in our array.
  3. Inside the for loop, make an if statement that checks if zombieToOwner[zombieIndex] is equal to _owner. This will compare the two addresses to see if we have a match.
  4. Inside the if statement:
    1. Add the zombie's ID to our result array by setting result[resultIndex] equal to zombieIndex.
    2. Increment resultIndex by 1 (see the for loop example above).

Action

  • Would like to know your thoughts and feedback.
  • I can be the one making the changes and submitting the pull request.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions