Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chewhx opened this issue Jul 23, 2022 · 0 comments
Open

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

chewhx opened this issue Jul 23, 2022 · 0 comments

Comments

@chewhx
Copy link

chewhx commented Jul 23, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant