The logic of the Game

I am not native English Speaker maybe that’s why i couldn’t comprehend the Game Logic.
Why do we write the same code twice? I couldn’t understand that.
Can you explain this code to me?

*HiddenIndex is 0 btw.

qwe

1 Like

Each time the outer loop runs, the inner loop does a full run. This allows one to loop through all of the comparisons during each outer loop.

I was going to explain it further but my explanation was too long so I removed it.

There are indeed normally other ways eg could use a while loop and two separate integer variables possibly along with size or length or whatever. That mostly just gets into performance if its eg 1,000s of loops or just simply language use preferences by the programmer, or teacher.

Ultimately this is how they chose to do it. You’re free to do it some other way. Its not necessarily wrong to do so as long as it works to your expectations and provides a match when correct and no match when incorrect.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms