# Pseudocode Logic Doesn't Match Iterator Names

In the ‘Debugging 101’ video, the comments imply that we want to…

1. Loop through each guess character.
2. Loop through each hidden word character.
3. Check if the guess character (as defined in the first loop) is equal to the hidden word character (as defined in the second loop).
• if true, check if the indexes are equal.
• If they are equal, increment Bulls. If not, increment cows.

However, with the way his iterators are named, he is saying that we want to…

1. Loop through each hidden word character.
2. Loop through each guess character.

Line 47 is fine because he’s using the corresponding indices for Guess and MyHiddenWord. The issue just lies with the order in which he named the variables.

The following image shows how I believe it should be named. Ignore the other small changes I’ve made, just focus on the underlined variables.

As an example with the corrected code, here is what it would look like if the guess is “and” and the word is “ant”.

• what is Guess[0]?
• it’s ‘a’.
• does it match ‘a’ from “ant”? Yes! It’s in the same spot, so add a bull.
• does it match ‘n’ from “ant”? No.
• does it match ‘t’ from “ant”? No.
• what is Guess[1]?
• it’s ‘n’.
• does it match ‘a’ from “ant”? No.
• does it match ‘n’ from “ant”? Yes! It’s in the same spot, so add a bull.
• does it match ‘t’ from “ant”? No.
• what is Guess[2]?
• it’s ‘d’.
• does it match ‘a’ from “ant”? No.
• does it match ‘n’ from “ant”? No.
• does it match ‘t’ from “ant”? No.

In conclusion, the code works fine but it doesn’t match the logic that he introduced with his pseudocode. Feel free to let me know if you disagree or if I’ve made a mistake.

I think you are mistaken. Though the comments could be worded better, this is incorrect

``````* what is Guess[0]?
* it's 'a'.
* does it match 'a' from "ant"? Yes! It's in the same spot, so add a bull.
* does it match 'n' from "ant"? No.
* does it match 't' from "ant"? No.
* what is Guess[1]?
* it's 'n'.
* does it match 'a' from "ant"? No.
* does it match 'n' from "ant"? Yes! It's in the same spot, so add a bull.
* does it match 't' from "ant"? No.
* what is Guess[2]?
* it's 'd'.
* does it match 'a' from "ant"? No.
* does it match 'n' from "ant"? No.
* does it match 't' from "ant"? No.
``````

The inner loop is what will be looped through first.

Both permutations effectively do the same thing, but my concern was with how the instructor explained it. Your example is how he actually implemented it, but it’s the inverse of the method explained in his comments.

1. Your example: Increment through each hidden word character and compare all guess characters to it.
2. My example: Increment through each guess character and compare all hidden word characters to it.

I think the wording of the comments is fine, it’s just the order they’re in compared to the actual code.

Basically what I was trying to say is that the comments should all be moved down one and then add
`//Loop through HW`

@ben

i’m asking the same question to myself and when i’ve implemented the solution, i’ve inverted GChar and MHWChar