Hi,
I followed the course and was able to understand everything until here perfectly.
My first trouble began with the challenge for finishing the if loop. Also nested loops have not been discussed beforehand and the teacher was a little to quick in assuming everything is clear.
Now I got it all working, but I don’t quite understand the nested for loop in “english words”
int32 HiddenWordLength = MyHiddenWord.length();
for (int32 MyHiddenWordChar = 0; MyHiddenWordChar < HiddenWordLength; MyHiddenWordChar++) {
for (int32 GuessChar = 0; GuessChar < HiddenWordLength; GuessChar++) {
//compare letters against the hidden wordif (Guess[GuessChar] == MyHiddenWord[MyHiddenWordChar]) //if they match then { if (MyHiddenWordChar == GuessChar) //if they are in the same place { BullCowCount.Bulls++; } else //if they are not in the same place { BullCowCount.Cows++; } } // if they are in the same place //incriment bulls //if they are not (else) //incriment cows }
}
From what I understand from nested for loops before is, that the outer loop only proceeds once the inner loop is completely finished (or interrupted).
Let’s say the hidden word indeed is “ant” and my guess is “and”
- So the first check would be my guessed “a” getting compared to the hidden “a”. True, Bulls++.
What then?
-
It increments GuessChar by one, and basically compares my guessed “n” to the hidden “a”? False, no else defined
-
Increment again, check guessed “d” to compare with hidden “a”, False, no else defined.
Now MyHiddenWordChar increments by 1 and it starts again with comparing my guessed “a” to the hidden “n”.
And so forth?
Just trying to understand, that is what’s going on here, before I continue. And I am pretty sure there will be some improvements in further lessons.
Thanks!
Chris