What exactly is the "if statement" doing?

So I somewhat understand the code, but does GChar compare each of its elements to all 5 of the HWChar’s elements via the “if statement”? Or does it compare say Guess element 0 to HiddenWord element 0 at the same time since they’re both loops running at the same time, then cycle to comparing element 1 to element 1?

	for (int32 HWChar = 0; HWChar < HiddenWordLength; HWChar++) // initializing HWChar (hidden word) 
	{
		for (int32 GChar = 0; GChar < HiddenWordLength; GChar++) // initializing GChar (guess) 
		{
			// if they match then
			if (Guess[GChar] == MyHiddenWord[HWChar]) { // If ANY element of Guess matches MyHiddenWord then
				if (HWChar == GChar) { // check to see if they're in the same place
					BullCowCount.Bulls++; // must be a bull 
				}
				else { // any other match, that's not a specific element match, has to be a cow
					BullCowCount.Cows++; // must be a cow 
				}

			}
		}
	}

I’ll just put this in the code itself:


for (int32 HWChar = 0; HWChar < HiddenWordLength; HWChar++) // initializing HWChar (hidden word) 
{
	for (int32 GChar = 0; GChar < HiddenWordLength; GChar++) // initializing GChar (guess) 
	{ //This I find confusing; because you are creating Gchar everytime regardless.
		
		if (Guess[GChar] == MyHiddenWord[HWChar]) 
        {//Here You're saying that IF the Gchar  is equal to HWchar in their respective 
        //words then do what is in the order

		    if (HWChar == GChar) 
                {// So this would be the first thing in order to do ;  now you're saying
                 // IF these two numbers are = to each other (not the characters) then:
					BullCowCount.Bulls++;
				}
                // IF the two numbers (again not the characters you wanted to compare)
               // do not equal each other : 
				else {
					BullCowCount.Cows++; 
				     }

		}
	}
}

Privacy & Terms